8000 Qualcomm AI Engine Direct - Add log utils for core module · linux-on-ibm-z/tensorflow@a47a227 · GitHub
[go: up one dir, main page]

Skip to content

Commit a47a227

Browse files
committed
Qualcomm AI Engine Direct - Add log utils for core module
Summary: - Implement default and android version of log utils for core module - Add test for log util - Use LogOff as default log level - Unify to use log util in core module
1 parent 91e0a9e commit a47a227

File tree

16 files changed

+367
-35
lines changed

16 files changed

+367
-35
lines changed

tensorflow/lite/experimental/litert/vendors/qualcomm/core/BUILD

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Copyright (c) Qualcomm Innovation Center, Inc.
2-
# All Rights Reserved.
1+
# Copyright (c) Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
33

44
package(
55
# copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
@@ -20,3 +20,8 @@ cc_library(
2020
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/wrappers:tensor_wrapper",
2121
],
2222
)
23+
24+
cc_library(
25+
name = "common",
26+
hdrs = ["common.h"],
27+
)

tensorflow/lite/experimental/litert/vendors/qualcomm/core/builders/BUILD

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Copyright (c) Qualcomm Innovation Center, Inc.
2-
# All Rights Reserved.
1+
# Copyright (c) Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
33

44
package(
55
# copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
@@ -119,6 +119,7 @@ cc_library(
119119
deps = [
120120
":op_builder",
121121
# copybara:uncomment "//third_party/qairt/latest:qnn_lib_headers",
122+
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/utils:log",
122123
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core:tensor_pool",
123124
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/wrappers:op_wrapper",
124125
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/wrappers:tensor_wrapper",
@@ -170,6 +171,7 @@ cc_library(
170171
deps = [
171172
":op_builder",
172173
# copybara:uncomment "//third_party/qairt/latest:qnn_lib_headers",
174+
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/utils:log",
173175
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core:tensor_pool",
174176
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/wrappers:op_wrapper",
175177
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/wrappers:tensor_wrapper",
@@ -204,6 +206,7 @@ cc_library(
204206
deps = [
205207
":op_builder",
206208
# copybara:uncomment "//third_party/qairt/latest:qnn_lib_headers",
209+
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/utils:log",
207210
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core:tensor_pool",
208211
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/wrappers:op_wrapper",
209212
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/wrappers:tensor_wrapper",
@@ -255,6 +258,7 @@ cc_library(
255258
deps = [
256259
":op_builder",
257260
# copybara:uncomment "//third_party/qairt/latest:qnn_lib_headers",
261+
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/utils:log",
258262
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core:tensor_pool",
259263
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/wrappers:op_wrapper",
260264
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/wrappers:tensor_wrapper",
@@ -323,6 +327,7 @@ cc_library(
323327
deps = [
324328
":op_builder",
325329
# copybara:uncomment "//third_party/qairt/latest:qnn_lib_headers",
330+
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/utils:log",
326331
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core:tensor_pool",
327332
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/wrappers:op_wrapper",
328333
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core/wrappers:tensor_wrapper",

tensorflow/lite/experimental/litert/vendors/qualcomm/core/builders/gather_op_builder.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// Copyright (c) Qualcomm Innovation Center, Inc.
2-
// All Rights Reserved.
1+
// Copyright (c) Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
33

44
#include "tensorflow/lite/experimental/litert/vendors/qualcomm/core/builders/gather_op_builder.h"
55

6+
#include "tensorflow/lite/experimental/litert/vendors/qualcomm/core/utils/log.h"
7+
68
namespace qnn {
79

810
std::vector<OpWrapper> BuildGatherOp(
@@ -12,7 +14,7 @@ std::vector<OpWrapper> BuildGatherOp(
1214
std::vector<OpWrapper> res;
1315

1416
if (batch_dims != 0) {
15-
// TODO: error log
17+
QNN_LOG_ERROR("The batch dimension of Gather OP is not equal to 0.");
1618
return res;
1719
}
1820

tensorflow/lite/experimental/litert/vendors/qualcomm/core/builders/mean_op_builder.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// Copyright (c) Qualcomm Innovation Center, Inc.
2-
// All Rights Reserved.
1+
// Copyright (c) Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
33

44
#include "tensorflow/lite/experimental/litert/vendors/qualcomm/core/builders/mean_op_builder.h"
55

6+
#include "tensorflow/lite/experimental/litert/vendors/qualcomm/core/utils/log.h"
7+
68
namespace qnn {
79

810
std::vector<OpWrapper> BuildMeanOp(TensorPool& tensor_pool,
@@ -13,7 +15,9 @@ std::vector<OpWrapper> BuildMeanOp(TensorPool& tensor_pool,
1315

1416
TensorWrapper& axis_tensor = inputs[1];
1517
if (!axis_tensor.IsTensorStatic() || axis_tensor.GetRank() != 1) {
16-
// TODO: error log
18+
QNN_LOG_ERROR(
19+
"The axis tensor is not static, or the rank of axis tensor is not "
20+
"equal to 1.");
1721
return res;
1822
}
1923

tensorflow/lite/experimental/litert/vendors/qualcomm/core/builders/reduce_op_builder.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// Copyright (c) Qualcomm Innovation Center, Inc.
2-
// All Rights Reserved.
1+
// Copyright (c) Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
33

44
#include "tensorflow/lite/experimental/litert/vendors/qualcomm/core/builders/reduce_op_builder.h"
55

6+
#include "tensorflow/lite/experimental/litert/vendors/qualcomm/core/utils/log.h"
7+
68
namespace qnn {
79

810
std::vector<OpWrapper> BuildReduceSumOp(
@@ -12,7 +14,9 @@ std::vector<OpWrapper> BuildReduceSumOp(
1214

1315
TensorWrapper& axis_tensor = inputs[1];
1416
if (!axis_tensor.IsTensorStatic() || axis_tensor.GetRank() != 1) {
15-
// TODO: error log
17+
QNN_LOG_ERROR(
18+
"The axis tensor is not static, or the rank of axis tensor is not "
19+
"equal to 1.");
1620
return res;
1721
}
1822

tensorflow/lite/experimental/litert/vendors/qualcomm/core/builders/slice_op_builder.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// Copyright (c) Qualcomm Innovation Center, Inc.
2-
// All Rights Reserved.
1+
// Copyright (c) Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
33

44
#include "tensorflow/lite/experimental/litert/vendors/qualcomm/core/builders/slice_op_builder.h"
55

6+
#include "tensorflow/lite/experimental/litert/vendors/qualcomm/core/utils/log.h"
7+
68
namespace qnn {
79

810
namespace {
@@ -20,7 +22,8 @@ std::vector<OpWrapper> BuildSliceOp(
2022
TensorWrapper& begin_tensor = inputs[1];
2123
TensorWrapper& size_tensor = inputs[2];
2224
if (!begin_tensor.IsTensorStatic() || !size_tensor.IsTensorStatic()) {
23-
// TODO: error log
25+
QNN_LOG_ERROR(
26+
"The begin tensor and size tensor of Slice OP is not static.");
2427
return res;
2528
}
2629

tensorflow/lite/experimental/litert/vendors/qualcomm/core/builders/transpose_op_builder.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// Copyright (c) Qualcomm Innovation Center, Inc.
2-
// All Rights Reserved.
1+
// Copyright (c) Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
33

44
#include "tensorflow/lite/experimental/litert/vendors/qualcomm/core/builders/transpose_op_builder.h"
55

6+
#include "tensorflow/lite/experimental/litert/vendors/qualcomm/core/utils/log.h"
7+
68
namespace qnn {
79

810
std::vector<OpWrapper> BuildTransposeOp(
@@ -12,7 +14,7 @@ std::vector<OpWrapper> BuildTransposeOp(
1214

1315
TensorWrapper& perm_tensor = inputs[1];
1416
if (!perm_tensor.IsTensorStatic()) {
15-
// TODO: error log
17+
QNN_LOG_ERROR("The param 'perm' of Transpose OP is not static.");
1618
return res;
1719
}
1820

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_LITERT_VENDORS_QUALCOMM_CORE_COMMON_H_
5+
#define TENSORFLOW_LITE_EXPERIMENTAL_LITERT_VENDORS_QUALCOMM_CORE_COMMON_H_
6+
7+
#ifdef __cplusplus
8+
extern "C" {
9+
#endif // __cplusplus
10+
11+
typedef enum LiteRtQnnLogLevel { // NOLINT(modernize-use-using)
12+
/// Disable delegate and QNN backend logging messages.
13+
kLogOff = 0,
14+
kLogLevelError = 1,
15+
kLogLevelWarn = 2,
16+
kLogLevelInfo = 3,
17+
kLogLevelVerbose = 4,
18+
kLogLevelDebug = 5,
19+
} LiteRtQnnLogLevel;
20+
21+
#ifdef __cplusplus
22+
}
23+
#endif // __cplusplus
24+
25+
#endif // TENSORFLOW_LITE_EXPERIMENTAL_LITERT_VENDORS_QUALCOMM_CORE_COMMON_H_
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
package(
5+
# copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
6+
default_visibility = ["//tensorflow/lite/experimental/litert/vendors/qualcomm:__subpackages__"],
7+
)
8+
9+
cc_library(
10+
name = "log",
11+
srcs = select({
12+
"//tensorflow:android": ["log_android.cc",],
13+
"//conditions:default": ["log_default.cc",],
14+
}),
15+
hdrs = ["log.h"],
16+
tags = [
17+
# Don't build/test in OS until qnn is available.
18+
"nobuilder",
19+
],
20+
linkopts = select({
21+
"//tensorflow:android": ["-llog"],
22+
"//conditions:default": [],
23+
}),
24+
deps = [
25+
"//tensorflow/lite/experimental/litert/vendors/qualcomm/core:common",
26+
],
27+
)
28+
29+
cc_test(
30+
name = "utils_test",
31+
srcs = [
32+
"utils_test.cc",
33+
],
34+
tags = [
35+
# Tests with ungrte deps do not currently work on forge.
36+
"no-remote-exec",
37+
"notap",
38+
# Don't build/test in OS until qnn is available.
39+
"nobuilder",
40+
"no_oss",
41+
# Sanitizer runtime doesn't work with anything that loads libQnnHtp.so.
42+
"nosan",
43+
],
44+
deps = [
45+
":log",
46+
"@com_google_googletest//:gtest_main",
47+
],
48+
)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_LITERT_VENDORS_QUALCOMM_CORE_UTILS_LOG_H_
5+
#define TENSORFLOW_LITE_EXPERIMENTAL_LITERT_VENDORS_QUALCOMM_CORE_UTILS_LOG_H_
6+
7+
#include <cstdio>
8+
9+
#include "tensorflow/lite/experimental/litert/vendors/qualcomm/core/common.h"
10+
11+
namespace qnn {
12+
13+
class QNNLogger {
14+
public:
15+
// Logging hook that takes variadic args.
16+
static void Log(LiteRtQnnLogLevel severity, const char* format, ...);
17+
18+
// Set file descriptor
19+
static void SetLogFilePointer(FILE* fp);
20+
21+
// Set log level
22+
static void SetLogLevel(LiteRtQnnLogLevel log_level);
23+
24+
private:
25+
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
26+
static FILE* log_file_pointer_;
27+
static LiteRtQnnLogLevel log_level_;
28+
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
29+
};
30+
} // namespace qnn
31+
32+
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
33+
#define QNN_LOG_VERBOSE(format, ...) \
34+
::qnn::QNNLogger::Log(kLogLevelVerbose, ("VERBOSE: [Qnn] " format), \
35+
##__VA_ARGS__);
36+
37+
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
38+
#define QNN_LOG_INFO(format, ...) \
39+
::qnn::QNNLogger::Log(kLogLevelInfo, ("INFO: [Qnn] " format), ##__VA_ARGS__);
40+
41+
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
42+
#define QNN_LOG_WARNING(format, ...) \
43+
::qnn::QNNLogger::Log(kLogLevelWarn, ("WARNING: [Qnn] " format), \
44+
##__VA_ARGS__);
45+
46+
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
47+
#define QNN_LOG_ERROR(format, ...) \
48+
::qnn::QNNLogger::Log(kLogLevelError, ("ERROR: [Qnn] " format), \
49+
##__VA_ARGS__);
50+
51+
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
52+
#define QNN_LOG_DEBUG(format, ...) \
53+
::qnn::QNNLogger::Log(kLogLevelDebug, ("DEBUG: [Qnn] " format), \
54+
##__VA_ARGS__);
55+
56+
#endif // TENSORFLOW_LITE_EXPERIMENTAL_LITERT_VENDORS_QUALCOMM_CORE_UTILS_LOG_H_

0 commit comments

Comments
 (0)
0