Skip to content

Commit b031073

Browse files
author
pytorchbot
committed
2024-09-21 nightly release (0eee42a)
1 parent ecb1ef1 commit b031073

File tree

14 files changed

+165
-118
lines changed

14 files changed

+165
-118
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,16 @@
1010

1111
#define PRECISION ${PRECISION}
1212

13+
#include "indexing_utils.h"
14+
1315
layout(std430) buffer;
1416

15-
${layout_declare_tensor(0, "w", "t_out", DTYPE, STORAGE)}
16-
${layout_declare_tensor(1, "r", "t_in", DTYPE, STORAGE)}
17+
${layout_declare_tensor(B, "w", "t_out", DTYPE, STORAGE)}
18+
${layout_declare_tensor(B, "r", "t_in", DTYPE, STORAGE)}
1719

18-
layout(set = 0, binding = 2) uniform PRECISION restrict CopyArgs {
19-
ivec3 range;
20-
int unused0;
21-
ivec3 src_offset;
22-
int unused1;
23-
ivec3 dst_offset;
24-
int unused2;
25-
};
20+
${layout_declare_ubo(B, "ivec3", "range", "ivec3", "src_offset", "ivec3", "dst_offset")}
21+
${layout_declare_ubo(B, "ivec4", "out_axis_map")}
22+
${layout_declare_ubo(B, "ivec4", "in_axis_map")}
2623

2724
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;
2825

@@ -36,5 +33,9 @@ void main() {
3633
return;
3734
}
3835

39-
imageStore(t_out, out_pos, texelFetch(t_in, in_pos, 0));
36+
write_texel_lpos(
37+
t_out,
38+
out_pos,
39+
load_texel_lpos(t_in, in_pos, in_axis_map),
40+
out_axis_map);
4041
}

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,13 @@ void add_copy_offset_node(
3333
add_dtype_suffix(kernel_name, *t_out);
3434

3535
const struct Block final {
36-
ivec3 range;
37-
int32_t unused0;
38-
ivec3 src_offset;
39-
int32_t unused1;
40-
ivec3 dst_offset;
41-
int32_t unused2;
36+
alignas(16) ivec3 range;
37+
alignas(16) ivec3 src_offset;
38+
alignas(16) ivec3 dst_offset;
4239
} offset_params{
4340
range,
44-
0,
4541
src_offset,
46-
0,
4742
dst_offset,
48-
0,
4943
};
5044

5145
auto shader = VK_KERNEL_FROM_STR(kernel_name);
@@ -61,7 +55,11 @@ void add_copy_offset_node(
6155
{in, vkapi::MemoryAccessType::READ},
6256
},
6357
// Parameter buffers
64-
{graph.create_params_buffer(offset_params)},
58+
{
59+
graph.create_params_buffer(offset_params),
60+
t_out->axis_map_ubo(),
61+
t_in->axis_map_ubo(),
62+
},
6563
// Specialization Constants
6664
{}));
6765
}

docs/source/apple-runtime.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ Link your binary with the ExecuTorch runtime and any backends or kernels used by
1919

2020
## Integration
2121

22+
### Setup
23+
24+
#### CMake
25+
26+
Building the Xcode project requires CMake. Installing via homebrew does not
27+
typically work; instead, install the packaged application and commandline tools
28+
globally:
29+
30+
1. Download the macOS `.dmg` installer from https://cmake.org/download
31+
2. Open the `.dmg`
32+
3. Drag the CMake app to the `/Applications` folder
33+
4. In a terminal, install the command line tools: `sudo /Applications/CMake.app/Contents/bin/cmake-gui --install`
34+
2235
### Swift Package Manager
2336

2437
The prebuilt ExecuTorch runtime, backend, and kernels are available as a [Swift PM](https://www.swift.org/documentation/package-manager/) package.

examples/arm/executor_runner/arm_executor_runner.cpp

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,23 @@ char* model_pte = nullptr;
4545
#include "model_pte.h"
4646
#endif
4747

48-
using namespace exec_aten;
49-
using namespace std;
50-
using torch::executor::Error;
51-
using torch::executor::Result;
48+
using executorch::aten::ScalarType;
49+
using executorch::aten::Tensor;
50+
using executorch::aten::TensorImpl;
51+
using executorch::extension::BufferCleanup;
52+
using executorch::extension::BufferDataLoader;
53+
using executorch::runtime::Error;
54+
using executorch::runtime::EValue;
55+
using executorch::runtime::HierarchicalAllocator;
56+
using executorch::runtime::MemoryAllocator;
57+
using executorch::runtime::MemoryManager;
58+
using executorch::runtime::Method;
59+
using executorch::runtime::MethodMeta;
60+
using executorch::runtime::Program;
61+
using executorch::runtime::Result;
62+
using executorch::runtime::Span;
63+
using executorch::runtime::Tag;
64+
using executorch::runtime::TensorInfo;
5265

5366
#define METHOD_ALLOCATOR_POOL_SIZE (70 * 1024 * 1024)
5467
unsigned char __attribute__((
@@ -86,11 +99,10 @@ void et_pal_emit_log_message(
8699
}
87100

88101
namespace {
89-
using namespace torch::executor;
90102

91-
Result<util::BufferCleanup> prepare_input_tensors(
103+
Result<BufferCleanup> prepare_input_tensors(
92104
Method& method,
93-
torch::executor::MemoryAllocator& allocator,
105+
MemoryAllocator& allocator,
94106
std::vector<std::pair<char*, size_t>>& input_buffers) {
95107
MethodMeta method_meta = method.method_meta();
96108
size_t num_inputs = method_meta.num_inputs();
@@ -175,18 +187,18 @@ Result<util::BufferCleanup> prepare_input_tensors(
175187
ET_LOG(
176188
Error, "Failed to prepare input %zu: 0x%" PRIx32, i, (uint32_t)err);
177189
// The BufferCleanup will free the inputs when it goes out of scope.
178-
util::BufferCleanup cleanup({inputs, num_allocated});
190+
BufferCleanup cleanup({inputs, num_allocated});
179191
return err;
180192
}
181193
}
182-
return util::BufferCleanup({inputs, num_allocated});
194+
return BufferCleanup({inputs, num_allocated});
183195
}
184196

185197
#ifdef SEMIHOSTING
186198

187199
std::pair<char*, size_t> read_binary_file(
188200
const char* filename,
189-
torch::executor::MemoryAllocator& allocator) {
201+
MemoryAllocator& allocator) {
190202
FILE* fp = fopen(filename, "rb");
191203
if (!fp) {
192204
ET_LOG(
@@ -238,13 +250,13 @@ int main(int argc, const char* argv[]) {
238250
(void)argv;
239251
#endif
240252

241-
torch::executor::runtime_init();
253+
executorch::runtime::runtime_init();
242254
std::vector<std::pair<char*, size_t>> input_buffers;
243255
size_t pte_size = sizeof(model_pte);
244256

245257
#ifdef SEMIHOSTING
246258
const char* output_basename = nullptr;
247-
torch::executor::MemoryAllocator input_allocator(
259+
MemoryAllocator input_allocator(
248260
input_allocation_pool_size, input_allocation_pool);
249261

250262
/* parse input parameters */
@@ -277,10 +289,9 @@ int main(int argc, const char* argv[]) {
277289
}
278290
#endif
279291
ET_LOG(Info, "Model in %p %c", model_pte, model_pte[0]);
280-
auto loader = torch::executor::util::BufferDataLoader(model_pte, pte_size);
292+
auto loader = BufferDataLoader(model_pte, pte_size);
281293
ET_LOG(Info, "Model PTE file loaded. Size: %lu bytes.", pte_size);
282-
Result<torch::executor::Program> program =
283-
torch::executor::Program::load(&loader);
294+
Result<Program> program = Program::load(&loader);
284295
if (!program.ok()) {
285296
ET_LOG(
286297
Info,
@@ -299,8 +310,7 @@ int main(int argc, const char* argv[]) {
299310
}
300311
ET_LOG(Info, "Running method %s", method_name);
301312

302-
Result<torch::executor::MethodMeta> method_meta =
303-
program->method_meta(method_name);
313+
Result<MethodMeta> method_meta = program->method_meta(method_name);
304314
if (!method_meta.ok()) {
305315
ET_LOG(
306316
Info,
@@ -309,13 +319,11 @@ int main(int argc, const char* argv[]) {
309319
(unsigned int)method_meta.error());
310320
}
311321

312-
torch::executor::MemoryAllocator method_allocator{
313-
torch::executor::MemoryAllocator(
314-
METHOD_ALLOCATOR_POOL_SIZE, method_allocation_pool)};
322+
MemoryAllocator method_allocator(
323+
METHOD_ALLOCATOR_POOL_SIZE, method_allocation_pool);
315324

316325
std::vector<uint8_t*> planned_buffers; // Owns the memory
317-
std::vector<torch::executor::Span<uint8_t>>
318-
planned_spans; // Passed to the allocator
326+
std::vector<Span<uint8_t>> planned_spans; // Passed to the allocator
319327
size_t num_memory_planned_buffers = method_meta->num_memory_planned_buffers();
320328

321329
for (size_t id = 0; id < num_memory_planned_buffers; ++id) {
@@ -330,17 +338,16 @@ int main(int argc, const char* argv[]) {
330338
planned_spans.push_back({planned_buffers.back(), buffer_size});
331339
}
332340

333-
torch::executor::HierarchicalAllocator planned_memory(
341+
HierarchicalAllocator planned_memory(
334342
{planned_spans.data(), planned_spans.size()});
335343

336-
torch::executor::MemoryAllocator temp_allocator(
344+
MemoryAllocator temp_allocator(
337345
temp_allocation_pool_size, temp_allocation_pool);
338346

339-
torch::executor::MemoryManager memory_manager(
347+
MemoryManager memory_manager(
340348
&method_allocator, &planned_memory, &temp_allocator);
341349

342-
Result<torch::executor::Method> method =
343-
program->load_method(method_name, &memory_manager);
350+
Result<Method> method = program->load_method(method_name, &memory_manager);
344351
if (!method.ok()) {
345352
ET_LOG(
346353
Info,
@@ -379,7 +386,7 @@ int main(int argc, const char* argv[]) {
379386
ET_LOG(Info, "Model executed successfully.");
380387
}
381388

382-
std::vector<torch::executor::EValue> outputs(method->outputs_size());
389+
std::vector<EValue> outputs(method->outputs_size());
383390
ET_LOG(Info, "%zu outputs: ", outputs.size());
384391
status = method->get_outputs(outputs.data(), outputs.size());
385392
ET_CHECK(status == Error::Ok);

examples/demo-apps/android/LlamaDemo/docs/delegates/mediatek_README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Before continuing forward, make sure to modify the tokenizer, token embedding, a
112112
Prior to deploying the files on device, make sure to modify the tokenizer, token embedding, and model file names in examples/mediatek/executor_runner/run_llama3_sample.sh reflect what was generated during the Export Llama Model step.
113113

114114
<p align="center">
115-
<img src="../screenshots/mtk_changes_to_shell_file.png" width=600>
115+
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/mtk_changes_to_shell_file.png" width=600>
116116
</p>
117117

118118
In addition, create a sample_prompt.txt file with a prompt. This will be deployed to the device in the next step.
@@ -150,7 +150,7 @@ adb shell
150150
```
151151

152152
<p align="center">
153-
<img src="../screenshots/mtk_output.png" width=800>
153+
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/mtk_output.png" width=800>
154154
</p>
155155

156156
## Reporting Issues

examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ popd
221221
If the app successfully run on your device, you should see something like below:
222222

223223
<p align="center">
224-
<img src="https://github.com/pytorch/executorch/blob/main/examples/demo-apps/android/LlamaDemo/docs/screenshots/opening_the_app_details.png" width=800>
224+
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/opening_the_app_details.png" width=800>
225225
</p>
226226

227227
## Reporting Issues

examples/demo-apps/android/LlamaDemo/docs/delegates/xnnpack_README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ popd
149149
If the app successfully run on your device, you should see something like below:
150150

151151
<p align="center">
152-
<img src="../screenshots/opening_the_app_details.png" width=800>
152+
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/opening_the_app_details.png" width=800>
153153
</p>
154154

155155
## Reporting Issues

examples/demo-apps/apple_ios/LLaMA/docs/delegates/mps_README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ Note: To access logs, link against the Debug build of the ExecuTorch runtime, i.
9595
For more details integrating and Running ExecuTorch on Apple Platforms, checkout this [link](https://pytorch.org/executorch/main/apple-runtime.html).
9696

9797
<p align="center">
98-
<img src="../screenshots/ios_demo_app_swift_pm.png" alt="iOS LLaMA App Swift PM" width="600">
98+
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/ios_demo_app_swift_pm.png" alt="iOS LLaMA App Swift PM" width="600">
9999
</p>
100100

101101
Then select which ExecuTorch framework should link against which target.
102102

103103
<p align="center">
104-
<img src="../screenshots/ios_demo_app_choosing_package.png" alt="iOS LLaMA App Choosing package" width="600">
104+
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/ios_demo_app_choosing_package.png" alt="iOS LLaMA App Choosing package" width="600">
105105
</p>
106106

107107
Click “Run” to build the app and run in on your iPhone. If the app successfully run on your device, you should see something like below:
108108

109109
<p align="center">
110-
<img src="../screenshots/ios_demo_app_mps.jpg" alt="iOS LLaMA App mps" width="300">
110+
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/ios_demo_app_mps.jpg" alt="iOS LLaMA App mps" width="300">
111111
</p>
112112

113113
## Reporting Issues

examples/demo-apps/apple_ios/LLaMA/docs/delegates/xnnpack_README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,25 @@ Note: To access logs, link against the Debug build of the ExecuTorch runtime, i.
9595
For more details integrating and Running ExecuTorch on Apple Platforms, checkout this [link](https://pytorch.org/executorch/main/apple-runtime.html).
9696

9797
<p align="center">
98-
<img src="../screenshots/ios_demo_app_swift_pm.png" alt="iOS LLaMA App Swift PM" width="600">
98+
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/ios_demo_app_swift_pm.png" alt="iOS LLaMA App Swift PM" width="600">
9999
</p>
100100

101101
Then select which ExecuTorch framework should link against which target.
102102

103103
<p align="center">
104-
<img src="../screenshots/ios_demo_app_choosing_package.png" alt="iOS LLaMA App Choosing package" width="600">
104+
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/ios_demo_app_choosing_package.png" alt="iOS LLaMA App Choosing package" width="600">
105105
</p>
106106

107107
Click “Run” to build the app and run in on your iPhone. If the app successfully run on your device, you should see something like below:
108108

109109
<p align="center">
110-
<img src="../screenshots/ios_demo_app.jpg" alt="iOS LLaMA App" width="300">
110+
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/ios_demo_app.jpg" alt="iOS LLaMA App" width="300">
111111
</p>
112112

113113
For Llava 1.5 models, you can select and image (via image/camera selector button) before typing prompt and send button.
114114

115115
<p align="center">
116-
<img src="../screenshots/ios_demo_app_llava.jpg" alt="iOS LLaMA App" width="300">
116+
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/ios_demo_app_llava.jpg" alt="iOS LLaMA App" width="300">
117117
</p>
118118

119119
## Reporting Issues

examples/models/phi-3-mini/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int main(int32_t argc, char** argv) {
4242

4343
int32_t seq_len = FLAGS_seq_len;
4444

45-
::torch::executor::Runner runner(model_path, tokenizer_path, temperature);
45+
example::Runner runner(model_path, tokenizer_path, temperature);
4646

4747
runner.generate(prompt, seq_len);
4848

0 commit comments

Comments
 (0)