Skip to content

Commit f8d2baf

Browse files
committed
Update
[ghstack-poisoned]
2 parents 497ea70 + 225d5a6 commit f8d2baf

File tree

24 files changed

+471
-116
lines changed

24 files changed

+471
-116
lines changed

.github/workflows/pull.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,3 +762,66 @@ jobs:
762762
763763
# Test selective build
764764
PYTHON_EXECUTABLE=python bash examples/wasm/test_build_wasm.sh
765+
766+
unittest-nxp-neutron:
767+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
768+
permissions:
769+
id-token: write
770+
contents: read
771+
with:
772+
runner: linux.2xlarge
773+
docker-image: executorch-ubuntu-22.04-clang12
774+
submodules: 'recursive'
775+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
776+
timeout: 90
777+
script: |
778+
set -eux
779+
780+
# The generic Linux job chooses to use base env, not the one setup by the image
781+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
782+
conda activate "${CONDA_ENV}"
783+
784+
# Build and install Executorch
785+
PYTHON_EXECUTABLE=python \
786+
CMAKE_ARGS="-DEXECUTORCH_BUILD_NXP_NEUTRON=ON" \
787+
.ci/scripts/setup-linux.sh --build-tool "cmake"
788+
789+
# Install test requirements
790+
pip install -r backends/nxp/requirements-tests.txt
791+
792+
# Run pytest
793+
PYTHON_EXECUTABLE=python bash backends/nxp/run_unittests.sh
794+
795+
# Run aot example:
796+
PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh
797+
798+
799+
nxp-build-test:
800+
name: nxp-build-test
801+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
802+
permissions:
803+
id-token: write
804+
contents: read
805+
with:
806+
runner: linux.2xlarge
807+
docker-image: executorch-ubuntu-22.04-arm-sdk
808+
submodules: 'recursive'
809+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
810+
timeout: 90
811+
script: |
812+
# The generic Linux job chooses to use base env, not the one setup by the image
813+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
814+
conda activate "${CONDA_ENV}"
815+
816+
# Build
817+
cmake -DEXECUTORCH_BUILD_NXP_NEUTRON=ON -Bcmake-out .
818+
cmake --build cmake-out --target executorch_delegate_neutron --config Release
819+
820+
# Build check for the neutron backend library
821+
lib_neutron="cmake-out/backends/nxp/libexecutorch_delegate_neutron.a"
822+
if [ -f $lib_neutron ]; then
823+
echo "Neutron backend library built."
824+
else
825+
echo "Neutron backend library not found!"
826+
exit 1
827+
fi

.github/workflows/trunk.yml

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -302,36 +302,6 @@ jobs:
302302
exit 1
303303
fi
304304
305-
nxp-build-test:
306-
name: nxp-build-test
307-
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
308-
permissions:
309-
id-token: write
310-
contents: read
311-
with:
312-
runner: linux.2xlarge
313-
docker-image: executorch-ubuntu-22.04-arm-sdk
314-
submodules: 'recursive'
315-
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
316-
timeout: 90
317-
script: |
318-
# The generic Linux job chooses to use base env, not the one setup by the image
319-
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
320-
conda activate "${CONDA_ENV}"
321-
322-
# Build
323-
cmake -DEXECUTORCH_BUILD_NXP_NEUTRON=ON -Bcmake-out .
324-
cmake --build cmake-out --target executorch_delegate_neutron --config Release
325-
326-
# Build check for the neutron backend library
327-
lib_neutron="cmake-out/backends/nxp/libexecutorch_delegate_neutron.a"
328-
if [ -f $lib_neutron ]; then
329-
echo "Neutron backend library built."
330-
else
331-
echo "Neutron backend library not found!"
332-
exit 1
333-
fi
334-
335305
test-coreml-delegate:
336306
name: test-coreml-delegate
337307
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
@@ -771,35 +741,3 @@ jobs:
771741
build-mode: Release
772742
build-tool: cmake
773743
docker-image: executorch-ubuntu-22.04-clang12
774-
775-
unittest-nxp-neutron:
776-
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
777-
permissions:
778-
id-token: write
779-
contents: read
780-
with:
781-
runner: linux.2xlarge
782-
docker-image: executorch-ubuntu-22.04-clang12
783-
submodules: 'recursive'
784-
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
785-
timeout: 90
786-
script: |
787-
set -eux
788-
789-
# The generic Linux job chooses to use base env, not the one setup by the image
790-
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
791-
conda activate "${CONDA_ENV}"
792-
793-
# Build and install Executorch
794-
PYTHON_EXECUTABLE=python \
795-
CMAKE_ARGS="-DEXECUTORCH_BUILD_NXP_NEUTRON=ON" \
796-
.ci/scripts/setup-linux.sh --build-tool "cmake"
797-
798-
# Install test requirements
799-
pip install -r backends/nxp/requirements-tests.txt
800-
801-
# Run pytest
802-
PYTHON_EXECUTABLE=python bash backends/nxp/run_unittests.sh
803-
804-
# Run aot example:
805-
PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh

backends/vulkan/runtime/graph/ComputeGraph.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,12 @@ class ComputeGraph final {
424424
// Scalar Value Extraction
425425
//
426426

427+
bool is_scalar_or_none(const ValueRef idx) const {
428+
const Value& value = values_.at(idx);
429+
return value.isInt() || value.isDouble() || value.isBool() ||
430+
value.isNone();
431+
}
432+
427433
template <typename T>
428434
T extract_scalar(const ValueRef idx) {
429435
Value& value = values_.at(idx);
@@ -439,6 +445,15 @@ class ComputeGraph final {
439445
VK_THROW("Cannot extract scalar from Value with type ", value.type());
440446
}
441447

448+
template <typename T>
449+
T extract_scalar_or(const ValueRef idx, const T default_value) {
450+
Value& value = values_.at(idx);
451+
if (value.isNone()) {
452+
return default_value;
453+
}
454+
return extract_scalar<T>(idx);
455+
}
456+
442457
template <typename T>
443458
std::optional<T> extract_optional_scalar(const ValueRef idx) {
444459
if (val_is_none(idx)) {

backends/vulkan/runtime/graph/ops/glsl/transfer_buffer.glsl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#version 450 core
1010

1111
#define PRECISION ${PRECISION}
12+
#define UBO_PARAMS ${UBO_PARAMS}
1213

1314
#define VEC4_T ${texel_type(DTYPE)}
1415
#define T ${buffer_scalar_type(DTYPE)}
@@ -22,19 +23,27 @@ layout(std430) buffer;
2223
${layout_declare_tensor(B, "w", "t_out", DTYPE, "buffer")}
2324
${layout_declare_tensor(B, "r", "t_in", DTYPE, "buffer")}
2425

25-
$if OP_NAME == "slice":
26-
${layout_declare_ubo(B, "int", "start")}
27-
${layout_declare_ubo(B, "int", "step")}
26+
$if UBO_PARAMS:
27+
$if OP_NAME == "slice":
28+
${layout_declare_ubo(B, "int", "start")}
29+
${layout_declare_ubo(B, "int", "step")}
2830

29-
$if OP_NAME == "select":
30-
${layout_declare_ubo(B, "int", "index")}
31+
$if OP_NAME == "select":
32+
${layout_declare_ubo(B, "int", "index")}
3133

3234
layout(push_constant) uniform restrict Block {
3335
ivec4 in_sizes;
3436
ivec4 out_strides;
3537
ivec4 in_strides;
3638
int out_numel;
3739
int selected_dim;
40+
$if not UBO_PARAMS:
41+
$if OP_NAME == "slice":
42+
int start;
43+
int step;
44+
45+
$if OP_NAME == "select":
46+
int index;
3847
};
3948

4049
${layout_declare_spec_const(C, "int", "out_layout", "DEFAULT_LAYOUT")}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ transfer_buffer:
22
parameter_names_with_default_values:
33
DTYPE: float
44
OP_NAME: select
5+
UBO_PARAMS: False
56
generate_variant_forall:
67
DTYPE:
78
- VALUE: half
@@ -11,3 +12,9 @@ transfer_buffer:
1112
OP_NAME: select
1213
- NAME: slice_buffer
1314
OP_NAME: slice
15+
- NAME: select_ubo_buffer
16+
OP_NAME: select
17+
UBO_PARAMS: True
18+
- NAME: slice_ubo_buffer
19+
OP_NAME: slice
20+
UBO_PARAMS: True

backends/vulkan/runtime/graph/ops/glsl/transfer_texture.glsl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#version 450 core
1010

1111
#define PRECISION ${PRECISION}
12+
#define UBO_PARAMS ${UBO_PARAMS}
1213

1314
#define VEC4_T ${texel_type(DTYPE)}
1415
#define T ${buffer_scalar_type(DTYPE)}
@@ -23,17 +24,25 @@ layout(std430) buffer;
2324
${layout_declare_tensor(B, "w", "t_out", DTYPE, "texture3d")}
2425
${layout_declare_tensor(B, "r", "t_in", DTYPE, "texture3d")}
2526

26-
$if OP_NAME == "slice":
27-
${layout_declare_ubo(B, "int", "start")}
28-
${layout_declare_ubo(B, "int", "step")}
27+
$if UBO_PARAMS:
28+
$if OP_NAME == "slice":
29+
${layout_declare_ubo(B, "int", "start")}
30+
${layout_declare_ubo(B, "int", "step")}
2931

30-
$if OP_NAME == "select":
31-
${layout_declare_ubo(B, "int", "index")}
32+
$if OP_NAME == "select":
33+
${layout_declare_ubo(B, "int", "index")}
3234

3335
layout(push_constant) uniform restrict Block {
3436
ivec4 out_sizes;
3537
ivec4 in_sizes;
3638
int selected_dim;
39+
$if not UBO_PARAMS:
40+
$if OP_NAME == "slice":
41+
int start;
42+
int step;
43+
44+
$if OP_NAME == "select":
45+
int index;
3746
};
3847

3948
${layout_declare_spec_const(C, "int", "out_layout", "DEFAULT_LAYOUT")}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ transfer_texture:
22
parameter_names_with_default_values:
33
DTYPE: float
44
OP_NAME: select
5+
UBO_PARAMS: False
56
generate_variant_forall:
67
DTYPE:
78
- VALUE: half
@@ -11,3 +12,9 @@ transfer_texture:
1112
OP_NAME: select
1213
- NAME: slice_texture3d
1314
OP_NAME: slice
15+
- NAME: select_ubo_texture3d
16+
OP_NAME: select
17+
UBO_PARAMS: True
18+
- NAME: slice_ubo_texture3d
19+
OP_NAME: slice
20+
UBO_PARAMS: True

backends/vulkan/runtime/graph/ops/impl/Transfer.cpp

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,52 @@ void add_transfer_copy_node(
4040

4141
int64_t dim_whcn = nchw_dim_to_whcn_dim(dim, ndim);
4242

43+
struct TransferParams {
44+
int32_t dim;
45+
int32_t index_or_start_ref;
46+
int32_t step_ref;
47+
} transfer_params{static_cast<int32_t>(dim_whcn), 0, 0};
48+
49+
const bool param_is_scalar = graph.is_scalar_or_none(index_or_start_ref) &&
50+
(transfer_type == TransferType::SELECT ||
51+
graph.is_scalar_or_none(step_ref));
52+
4353
vkapi::ParamsBindList param_buffers;
44-
if (transfer_type == TransferType::SELECT) {
45-
param_buffers = {
46-
graph.get_or_create_int_param_buffer(index_or_start_ref, 0)};
47-
} else { // TransferType::SLICE
48-
param_buffers = {
49-
graph.get_or_create_int_param_buffer(index_or_start_ref, 0),
50-
graph.get_or_create_int_param_buffer(step_ref, 1)};
54+
if (!param_is_scalar) {
55+
if (transfer_type == TransferType::SELECT) {
56+
param_buffers = {
57+
graph.get_or_create_int_param_buffer(index_or_start_ref, 0)};
58+
} else { // TransferType::SLICE
59+
param_buffers = {
60+
graph.get_or_create_int_param_buffer(index_or_start_ref, 0),
61+
graph.get_or_create_int_param_buffer(step_ref, 1)};
62+
}
63+
} else {
64+
transfer_params.index_or_start_ref =
65+
graph.extract_scalar_or<int32_t>(index_or_start_ref, 0);
66+
if (transfer_type != TransferType::SELECT) {
67+
transfer_params.step_ref = graph.extract_scalar_or<int32_t>(step_ref, 1);
68+
}
5169
}
5270

53-
const struct TransferParams {
54-
const int32_t dim;
55-
} transfer_params{static_cast<int32_t>(dim_whcn)};
56-
5771
std::vector<PushConstantDataInfo> push_constants;
72+
push_constants.reserve(graph.is_buffer_storage(out) ? 5 : 3);
5873

5974
if (graph.is_buffer_storage(out)) {
60-
push_constants = {
61-
graph.sizes_pc_of(in),
62-
graph.strides_pc_of(out),
63-
graph.strides_pc_of(in),
64-
graph.numel_pc_of(out),
65-
PushConstantDataInfo(&transfer_params, sizeof(transfer_params))};
75+
push_constants.emplace_back(graph.sizes_pc_of(in));
76+
push_constants.emplace_back(graph.strides_pc_of(out));
77+
push_constants.emplace_back(graph.strides_pc_of(in));
78+
push_constants.emplace_back(graph.numel_pc_of(out));
6679
} else {
67-
push_constants = {
68-
graph.sizes_pc_of(out),
69-
graph.sizes_pc_of(in),
70-
PushConstantDataInfo(&transfer_params, sizeof(transfer_params))};
80+
push_constants.emplace_back(graph.sizes_pc_of(out));
81+
push_constants.emplace_back(graph.sizes_pc_of(in));
82+
}
83+
84+
if (param_is_scalar) {
85+
push_constants.emplace_back(&transfer_params, sizeof(transfer_params));
86+
} else {
87+
push_constants.emplace_back(
88+
&transfer_params.dim, sizeof(transfer_params.dim));
7189
}
7290

7391
vkapi::SpecVarList spec_vars = {
@@ -82,6 +100,9 @@ void add_transfer_copy_node(
82100
} else { // TransferType::SLICE
83101
kernel_name = "slice";
84102
}
103+
if (!param_is_scalar) {
104+
kernel_name += "_ubo";
105+
}
85106
add_storage_type_suffix(kernel_name, graph.storage_type_of(out));
86107
add_dtype_suffix(kernel_name, graph.dtype_of(out));
87108

backends/xnnpack/cmake/Dependencies.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI)
8383
KLEIDIAI_LIBRARY kleidiai
8484
PATHS "${CMAKE_CURRENT_BINARY_DIR}/XNNPACK/kleidiai-source"
8585
)
86-
if(not KLEIDIAI_LIBRARY)
87-
message(FATAL_ERROR "Can't find KleidiAI")
86+
if(KLEIDIAI_LIBRARY)
87+
message(WARNING "Can't find KleidiAI, skipping install")
88+
install(FILES ${KLEIDIAI_LIBRARY} PUBLIC_HEADER
89+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
90+
)
8891
endif()
89-
install(FILES ${KLEIDIAI_LIBRARY} PUBLIC_HEADER
90-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
91-
)
9292
endif()

0 commit comments

Comments
 (0)