Skip to content

Commit 3ab6302

Browse files
author
pytorchbot
committed
2024-11-01 nightly release (465170f)
1 parent 7072212 commit 3ab6302

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1058
-249
lines changed

backends/qualcomm/runtime/backends/QnnFunctionInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class QnnInterface {
7070
DEFINE_SHIM_FUNCTION_INTERFACE(log_set_log_level, logSetLogLevel);
7171
// --------- QnnProfile ---------
7272
DEFINE_SHIM_FUNCTION_INTERFACE(profile_create, profileCreate);
73+
DEFINE_SHIM_FUNCTION_INTERFACE(profile_set_config, profileSetConfig);
7374
DEFINE_SHIM_FUNCTION_INTERFACE(profile_get_events, profileGetEvents);
7475
DEFINE_SHIM_FUNCTION_INTERFACE(profile_get_sub_events, profileGetSubEvents);
7576
DEFINE_SHIM_FUNCTION_INTERFACE(profile_get_event_data, profileGetEventData);

backends/qualcomm/runtime/backends/QnnGraphCommon.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class QnnGraph {
5252

5353
Qnn_ErrorHandle_t GraphFinalize() {
5454
return implementation_.GetQnnInterface().qnn_graph_finalize(
55-
handle_, nullptr /* profile_handle */, nullptr /* signal_handle */);
55+
handle_, profile_->GetHandle(), nullptr /* signal_handle */);
5656
};
5757
Qnn_ErrorHandle_t ProfileExecuteData(
5858
executorch::runtime::EventTracer* event_tracer) {
@@ -62,6 +62,10 @@ class QnnGraph {
6262
return handle_;
6363
}
6464

65+
QnnProfile* GetProfile() {
66+
return profile_.get();
67+
}
68+
6569
protected:
6670
virtual executorch::runtime::Error MakeConfig(
6771
std::vector<const QnnGraph_Config_t*>& config) {

backends/qualcomm/runtime/backends/QnnProfiler.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,21 @@ QnnProfile::QnnProfile(
1919
: handle_(nullptr), implementation_(implementation), backend_(backend) {
2020
if (profile_level != QnnExecuTorchProfileLevel::kProfileOff) {
2121
const QnnInterface& qnn_interface = implementation_.GetQnnInterface();
22+
23+
QnnProfile_Level_t qnnProfileLevel = 0;
24+
if (profile_level == QnnExecuTorchProfileLevel::kProfileBasic) {
25+
qnnProfileLevel = QNN_PROFILE_LEVEL_BASIC;
26+
} else if (
27+
profile_level == QnnExecuTorchProfileLevel::kProfileDetailed ||
28+
profile_level == QnnExecuTorchProfileLevel::kProfileOptrace) {
29+
qnnProfileLevel = QNN_PROFILE_LEVEL_DETAILED;
30+
} else {
31+
QNN_EXECUTORCH_LOG_WARN("Invalid profile level");
32+
return;
33+
}
34+
2235
Qnn_ErrorHandle_t error = qnn_interface.qnn_profile_create(
23-
backend_->GetHandle(), static_cast<int>(profile_level), &handle_);
36+
backend_->GetHandle(), qnnProfileLevel, &handle_);
2437
if (error != QNN_SUCCESS) {
2538
QNN_EXECUTORCH_LOG_WARN(
2639
"Failed to create profile_handle for backend "
@@ -31,6 +44,29 @@ QnnProfile::QnnProfile(
3144
// ignore error and continue to create backend handle...
3245
handle_ = nullptr;
3346
}
47+
48+
if (profile_level == QnnExecuTorchProfileLevel::kProfileOptrace) {
49+
if (handle_ == nullptr) {
50+
QNN_EXECUTORCH_LOG_WARN(
51+
"Prfoile handle is null, cannot enable optrace");
52+
return;
53+
}
54+
55+
QnnProfile_Config_t qnnProfileConfig = QNN_PROFILE_CONFIG_INIT;
56+
qnnProfileConfig.option = QNN_PROFILE_CONFIG_OPTION_ENABLE_OPTRACE;
57+
std::array<const QnnProfile_Config_t*, 2> profileConfigs = {
58+
&qnnProfileConfig, nullptr};
59+
error =
60+
qnn_interface.qnn_profile_set_config(handle_, profileConfigs.data());
61+
62+
if (error != QNN_SUCCESS) {
63+
QNN_EXECUTORCH_LOG_WARN(
64+
"Failed to set optrace for backend "
65+
" %u, error=%d",
66+
qnn_interface.GetBackendId(),
67+
QNN_GET_ERROR_CODE(error));
68+
}
69+
}
3470
}
3571
}
3672

backends/qualcomm/serialization/qnn_compile_spec_schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class QnnExecuTorchProfileLevel(IntEnum):
115115
kProfileOff = 0
116116
kProfileBasic = 1
117117
kProfileDetailed = 2
118+
kProfileOptrace = 3
118119

119120

120121
@dataclass

backends/qualcomm/serialization/schema.fbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ enum QnnExecuTorchProfileLevel: int {
135135
kProfileOff = 0,
136136
kProfileBasic,
137137
kProfileDetailed,
138+
kProfileOptrace,
138139
}
139140

140141
/// QNN backends currently supported

backends/qualcomm/utils/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ def generate_qnn_executorch_compiler_spec(
770770
online_prepare: bool = False,
771771
dump_intermediate_outputs: bool = False,
772772
profile: bool = False,
773+
optrace: bool = False,
773774
shared_buffer: bool = False,
774775
is_from_context_binary: bool = False,
775776
) -> List[CompileSpec]:
@@ -831,7 +832,9 @@ def generate_qnn_executorch_compiler_spec(
831832
if saver:
832833
qnn_executorch_options.library_path = "libQnnSaver.so"
833834

834-
if profile:
835+
if optrace:
836+
qnn_executorch_options.profile_level = QnnExecuTorchProfileLevel.kProfileOptrace
837+
elif profile:
835838
qnn_executorch_options.profile_level = (
836839
QnnExecuTorchProfileLevel.kProfileDetailed
837840
)

backends/vulkan/_passes/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ runtime.python_library(
1212
deps = [
1313
"//caffe2:torch",
1414
"//executorch/exir:pass_base",
15+
"//executorch/backends/vulkan:utils_lib",
1516
],
1617
)
1718

backends/vulkan/_passes/insert_prepack_nodes.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66

77
# pyre-strict
88

9+
from copy import deepcopy
10+
911
import executorch.backends.vulkan.custom_ops_lib # noqa
1012

1113
import torch
1214

1315
from executorch.backends.vulkan.op_registry import handles_own_prepacking
16+
from executorch.backends.vulkan.utils import is_param_node
1417

1518
from executorch.exir.dialects._ops import ops as exir_ops
1619

17-
from torch._export.utils import is_buffer, is_param
1820
from torch.export import ExportedProgram
1921

2022

@@ -29,25 +31,8 @@ def insert_prepack_nodes(program: ExportedProgram) -> ExportedProgram:
2931
argument into the operator implementation.
3032
"""
3133

32-
def is_get_attr_node(node: torch.fx.Node) -> bool:
33-
return isinstance(node, torch.fx.Node) and node.op == "get_attr"
34-
35-
def is_constant(node: torch.fx.Node) -> bool:
36-
return node.name in program.graph_signature.inputs_to_lifted_tensor_constants
37-
38-
def is_param_node(node: torch.fx.Node) -> bool:
39-
"""
40-
Check if the given node is a parameter within the exported program
41-
"""
42-
return (
43-
is_get_attr_node(node)
44-
or is_param(program, node)
45-
or is_buffer(program, node)
46-
or is_constant(node)
47-
)
48-
4934
def prepack_not_required(node: torch.fx.Node) -> bool:
50-
if not is_param_node(node):
35+
if not is_param_node(program, node):
5136
return True
5237

5338
for user in node.users:
@@ -69,9 +54,15 @@ def prepack_not_required(node: torch.fx.Node) -> bool:
6954
exir_ops.edge.et_vk.prepack.default,
7055
(node,),
7156
)
72-
prepack_node.meta["spec"] = node.meta["spec"]
57+
# This pass assumes that the SpecPropPass() has already been applied
58+
assert "spec" in node.meta
59+
# Validate that the original node is marked as a constant. Constant tensors
60+
# do not participate in memory planning.
61+
assert node.meta["spec"].const
62+
prepack_node.meta["val"] = node.meta["val"]
63+
prepack_node.meta["spec"] = deepcopy(node.meta["spec"])
7364
# Set the mem_obj_id to -1 to indicate that this node requires a dedicated
74-
# memory object. This pass must be executed AFTER the memory planning pass.
65+
# memory object.
7566
prepack_node.meta["spec"].mem_obj_id = -1
7667
node.replace_all_uses_with(prepack_node, lambda x, y=prepack_node: x != y)
7768

backends/vulkan/runtime/graph/ComputeGraph.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,22 @@ class ComputeGraph final {
612612
return {t, staging};
613613
}
614614

615+
/*
616+
* Add an input tensor with the specified properties along with its staging
617+
* buffer.
618+
*/
619+
inline IOValueRef add_input_tensor(
620+
const std::vector<int64_t>& sizes,
621+
const vkapi::ScalarType dtype,
622+
const utils::StorageType storage_type,
623+
const utils::GPUMemoryLayout memory_layout,
624+
const int64_t shared_object_idx = -1) {
625+
ValueRef t = add_tensor(
626+
sizes, dtype, storage_type, memory_layout, shared_object_idx);
627+
ValueRef staging = set_input_tensor(t);
628+
return {t, staging};
629+
}
630+
615631
SharedObject& get_shared_object(const int64_t idx);
616632

617633
//

backends/vulkan/runtime/graph/ops/glsl/bitw8_image_to_nchw_nobitw8buffer.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ bitw8_image_to_nchw_nobitw8buffer:
99
STORAGE: texture3d
1010
DTYPE: int8
1111
generate_variant_forall:
12-
DTYPE:
13-
- VALUE: int8
14-
- VALUE: uint8
1512
STORAGE:
1613
- VALUE: texture2d
1714
- VALUE: texture3d
15+
DTYPE:
16+
- VALUE: int8
17+
- VALUE: uint8
1818
shader_variants:
1919
- NAME: bitw8_image_to_nchw_nobitw8buffer

0 commit comments

Comments
 (0)