Skip to content

Commit 6d75e44

Browse files
authored
Merge branch 'main' into revert-8997-change-985586
2 parents 31e4bfc + 51901f3 commit 6d75e44

File tree

11 files changed

+151
-80
lines changed

11 files changed

+151
-80
lines changed

.ci/docker/common/install_java.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -ex
9+
10+
apt-get update
11+
12+
apt-get install -y --no-install-recommends openjdk-17-jdk

.ci/docker/ubuntu/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ ARG BUCK2_VERSION
3030
COPY ./common/install_buck.sh install_buck.sh
3131
RUN bash ./install_buck.sh && rm install_buck.sh
3232

33+
# Install java
34+
COPY ./common/install_java.sh install_java.sh
35+
RUN bash ./install_java.sh && rm install_java.sh
36+
3337
# Setup user
3438
COPY ./common/install_user.sh install_user.sh
3539
RUN bash ./install_user.sh && rm install_user.sh

.github/workflows/doc-build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ jobs:
6868
make html
6969
cd ..
7070
71+
# Build javadoc:
72+
cd extension/android
73+
./gradlew javadoc
74+
cp -rf build/docs/javadoc "${RUNNER_DOCS_DIR}"
75+
cd ../..
76+
7177
# If it's main branch, add noindex tag to all .html files to exclude from Google Search indexing.
7278
echo "GitHub Ref: ${GITHUB_REF}"
7379
if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#include <executorch/backends/vulkan/runtime/graph/containers/PushConstantData.h>
10+
11+
namespace vkcompute {
12+
13+
uint32_t PushConstantDataInfo::write(
14+
void* dst,
15+
const uint32_t dst_offset,
16+
const uint32_t max_dst_size) const {
17+
if (tensorUniformData != nullptr) {
18+
return tensorUniformData->write_attribute(
19+
dst, dst_offset, max_dst_size, payload_.attr);
20+
}
21+
22+
VK_CHECK_COND(
23+
(dst_offset + payload_.dataSize) <= max_dst_size,
24+
"Attempting to write push constant data outside data boundary.");
25+
memcpy((uint8_t*)dst + dst_offset, payload_.data, payload_.dataSize);
26+
return payload_.dataSize;
27+
}
28+
29+
} // namespace vkcompute
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#pragma once
10+
11+
#include <executorch/backends/vulkan/runtime/api/api.h>
12+
13+
namespace vkcompute {
14+
15+
class ComputeGraph;
16+
17+
constexpr uint32_t kMaxPushConstantSize = 128;
18+
/*
19+
* Represents a push constant data entry
20+
* Which is either shared pointer to a tensor's uniform data with an attribute
21+
* Or data with a maximum size of 16 bytes
22+
*/
23+
class PushConstantDataInfo {
24+
std::shared_ptr<api::vTensor::UniformData> tensorUniformData;
25+
union Payload {
26+
struct {
27+
api::vTensor::Attribute attr;
28+
};
29+
struct {
30+
uint8_t data[16];
31+
uint32_t dataSize;
32+
};
33+
};
34+
35+
Payload payload_;
36+
37+
public:
38+
explicit PushConstantDataInfo(
39+
const std::shared_ptr<api::vTensor::UniformData>& tensorUniformData,
40+
api::vTensor::Attribute attr)
41+
: tensorUniformData(tensorUniformData) {
42+
payload_.attr = attr;
43+
}
44+
45+
explicit PushConstantDataInfo(
46+
const void* data,
47+
uint32_t dataLen,
48+
uint32_t pushConstantLen = 0)
49+
: tensorUniformData(nullptr) {
50+
VK_CHECK_COND(
51+
dataLen <= 16, "Single push constant data size must be <= 16 bytes");
52+
payload_.dataSize = pushConstantLen ? pushConstantLen : dataLen;
53+
memcpy(payload_.data, data, dataLen);
54+
}
55+
56+
/*
57+
* Function writes push constant data to the destination buffer
58+
*/
59+
uint32_t write(
60+
void* dst,
61+
const uint32_t dst_offset,
62+
const uint32_t max_dst_size) const;
63+
};
64+
65+
} // namespace vkcompute

backends/vulkan/runtime/graph/ops/DispatchNode.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,6 @@
1414

1515
namespace vkcompute {
1616

17-
uint32_t PushConstantDataInfo::write(
18-
void* dst,
19-
const uint32_t dst_offset,
20-
const uint32_t max_dst_size) const {
21-
if (tensorUniformData != nullptr) {
22-
return tensorUniformData->write_attribute(
23-
dst, dst_offset, max_dst_size, payload_.attr);
24-
}
25-
26-
VK_CHECK_COND(
27-
(dst_offset + payload_.dataSize) <= max_dst_size,
28-
"Attempting to write push constant data outside data boundary.");
29-
memcpy((uint8_t*)dst + dst_offset, payload_.data, payload_.dataSize);
30-
return payload_.dataSize;
31-
}
32-
3317
DispatchNode::DispatchNode(
3418
ComputeGraph& graph,
3519
const vkapi::ShaderInfo& shader,

backends/vulkan/runtime/graph/ops/DispatchNode.h

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <executorch/backends/vulkan/runtime/api/api.h>
1212

13+
#include <executorch/backends/vulkan/runtime/graph/containers/PushConstantData.h>
1314
#include <executorch/backends/vulkan/runtime/graph/containers/Value.h>
1415

1516
#include <executorch/backends/vulkan/runtime/graph/ops/ExecuteNode.h>
@@ -18,54 +19,6 @@ namespace vkcompute {
1819

1920
class ComputeGraph;
2021

21-
constexpr uint32_t kMaxPushConstantSize = 128;
22-
/*
23-
* Represents a push constant data entry
24-
* Which is either shared pointer to a tensor's uniform data with an attribute
25-
* Or data with a maximum size of 16 bytes
26-
*/
27-
class PushConstantDataInfo {
28-
std::shared_ptr<api::vTensor::UniformData> tensorUniformData;
29-
union Payload {
30-
struct {
31-
api::vTensor::Attribute attr;
32-
};
33-
struct {
34-
uint8_t data[16];
35-
uint32_t dataSize;
36-
};
37-
};
38-
39-
Payload payload_;
40-
41-
public:
42-
explicit PushConstantDataInfo(
43-
const std::shared_ptr<api::vTensor::UniformData>& tensorUniformData,
44-
api::vTensor::Attribute attr)
45-
: tensorUniformData(tensorUniformData) {
46-
payload_.attr = attr;
47-
}
48-
49-
explicit PushConstantDataInfo(
50-
const void* data,
51-
uint32_t dataLen,
52-
uint32_t pushConstantLen = 0)
53-
: tensorUniformData(nullptr) {
54-
VK_CHECK_COND(
55-
dataLen <= 16, "Single push constant data size must be <= 16 bytes");
56-
payload_.dataSize = pushConstantLen ? pushConstantLen : dataLen;
57-
memcpy(payload_.data, data, dataLen);
58-
}
59-
60-
/*
61-
* Function writes push constant data to the destination buffer
62-
*/
63-
uint32_t write(
64-
void* dst,
65-
const uint32_t dst_offset,
66-
const uint32_t max_dst_size) const;
67-
};
68-
6922
/*
7023
* Represents a single shader execution op in a ML model.
7124
*/

backends/vulkan/runtime/graph/ops/PrepackNode.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ PrepackNode::PrepackNode(
3232
const ValueRef tref,
3333
const ValueRef packed,
3434
const vkapi::ParamsBindList& params,
35-
const vkapi::SpecVarList& spec_vars)
35+
const vkapi::SpecVarList& spec_vars,
36+
const std::vector<PushConstantDataInfo>& push_constants)
3637
: shader_(shader),
3738
noop_shader_(get_noop_shader(graph, packed)),
3839
global_workgroup_size_(global_workgroup_size),
3940
local_workgroup_size_(local_workgroup_size),
4041
tref_(tref),
4142
packed_(packed),
4243
params_(params),
43-
spec_vars_(spec_vars) {
44+
spec_vars_(spec_vars),
45+
push_constants_(push_constants) {
4446
graph.update_descriptor_counts(shader, /*execute = */ false);
4547
graph.update_descriptor_counts(noop_shader_, /*execute = */ false);
4648
}
@@ -75,10 +77,20 @@ void PrepackNode::encode(ComputeGraph* graph) {
7577

7678
std::unique_lock<std::mutex> cmd_lock = context->dispatch_lock();
7779

80+
std::array<uint8_t, kMaxPushConstantSize> push_constants_data;
81+
uint32_t push_constants_offset = 0;
82+
83+
for (const auto& push_constant : push_constants_) {
84+
push_constants_offset += push_constant.write(
85+
push_constants_data.data(),
86+
push_constants_offset,
87+
kMaxPushConstantSize);
88+
}
89+
7890
{
7991
vkapi::PipelineBarrier pipeline_barrier{};
8092
vkapi::DescriptorSet descriptor_set = context->get_descriptor_set(
81-
shader_, local_workgroup_size_, spec_vars_, 0u);
93+
shader_, local_workgroup_size_, spec_vars_, push_constants_offset);
8294

8395
uint32_t idx = 0;
8496
bind_tensor_to_descriptor_set(
@@ -91,7 +103,12 @@ void PrepackNode::encode(ComputeGraph* graph) {
91103
bind_params_to_descriptor_set(params_, descriptor_set, idx);
92104

93105
context->register_shader_dispatch(
94-
descriptor_set, pipeline_barrier, shader_, global_workgroup_size_);
106+
descriptor_set,
107+
pipeline_barrier,
108+
shader_,
109+
global_workgroup_size_,
110+
push_constants_data.data(),
111+
push_constants_offset);
95112
}
96113

97114
// Submit a compute shader that performs a no-op with the packed tensor in

backends/vulkan/runtime/graph/ops/PrepackNode.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <executorch/backends/vulkan/runtime/api/api.h>
1212

13+
#include <executorch/backends/vulkan/runtime/graph/containers/PushConstantData.h>
1314
#include <executorch/backends/vulkan/runtime/graph/containers/Value.h>
1415

1516
namespace vkcompute {
@@ -34,7 +35,8 @@ class PrepackNode final {
3435
const ValueRef tref,
3536
const ValueRef packed,
3637
const vkapi::ParamsBindList& params,
37-
const vkapi::SpecVarList& spec_vars = {});
38+
const vkapi::SpecVarList& spec_vars = {},
39+
const std::vector<PushConstantDataInfo>& push_constants = {});
3840

3941
~PrepackNode() = default;
4042

@@ -54,6 +56,7 @@ class PrepackNode final {
5456
const ValueRef packed_;
5557
const vkapi::ParamsBindList params_;
5658
const vkapi::SpecVarList spec_vars_;
59+
const std::vector<PushConstantDataInfo> push_constants_;
5760

5861
private:
5962
api::StagingBuffer create_staging_buffer(ComputeGraph* graph);

extension/android/src/main/java/org/pytorch/executorch/EValue.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ private String getTypeName(int typeCode) {
177177
}
178178

179179
/**
180-
* Serializes an {@code EValue} into a byte array.
180+
* Serializes an {@code EValue} into a byte array. Note: This method is experimental and subject
181+
* to change without notice.
181182
*
182183
* @return The serialized byte array.
183-
* @apiNote This method is experimental and subject to change without notice.
184184
*/
185185
public byte[] toByteArray() {
186186
if (isNone()) {
@@ -212,11 +212,11 @@ public byte[] toByteArray() {
212212
}
213213

214214
/**
215-
* Deserializes an {@code EValue} from a byte[].
215+
* Deserializes an {@code EValue} from a byte[]. Note: This method is experimental and subject to
216+
* change without notice.
216217
*
217218
* @param bytes The byte array to deserialize from.
218219
* @return The deserialized {@code EValue}.
219-
* @apiNote This method is experimental and subject to change without notice.
220220
*/
221221
public static EValue fromByteArray(byte[] bytes) {
222222
ByteBuffer buffer = ByteBuffer.wrap(bytes);

0 commit comments

Comments
 (0)