-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pack buffer-backed tensors correctly when moving into and out of staging
Differential Revision: D61150844 Pull Request resolved: #4673
- Loading branch information
Showing
10 changed files
with
177 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
#version 450 core | ||
|
||
#define PRECISION ${PRECISION} | ||
|
35 changes: 35 additions & 0 deletions
35
backends/vulkan/runtime/graph/ops/glsl/buffer_to_nchw.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#version 450 core | ||
|
||
#define PRECISION ${PRECISION} | ||
|
||
#define T ${buffer_scalar_type(DTYPE)} | ||
|
||
#include "indexing_utils.h" | ||
|
||
${define_required_extensions(DTYPE)} | ||
|
||
layout(std430) buffer; | ||
|
||
${layout_declare_tensor(0, "w", "nchw_buf", DTYPE, STORAGE)} | ||
${layout_declare_tensor(1, "r", "t_in", DTYPE, STORAGE)} | ||
${layout_declare_ubo(2, "ivec4", "in_sizes")} | ||
${layout_declare_ubo(3, "ivec4", "in_strides")} | ||
${layout_declare_ubo(4, "int", "numel")} | ||
|
||
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; | ||
|
||
// This constant is unused in this shader but is kept so that the signature is | ||
// consistent with image_to_nchw. | ||
layout(constant_id = 3) const int UNUSED_packed_dim = W_DIM; | ||
|
||
void main() { | ||
int out_id = int(gl_GlobalInvocationID.x); | ||
if (out_id >= numel) { | ||
return; | ||
} | ||
|
||
ivec4 t_in_idx = from_nchw_buffer_i(out_id, in_sizes); | ||
const int in_id = to_buffer_id(t_in_idx, in_strides); | ||
|
||
nchw_buf[out_id] = t_in[in_id]; | ||
} |
18 changes: 18 additions & 0 deletions
18
backends/vulkan/runtime/graph/ops/glsl/buffer_to_nchw.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
buffer_to_nchw: | ||
parameter_names_with_default_values: | ||
DTYPE: float | ||
STORAGE: buffer | ||
generate_variant_forall: | ||
DTYPE: | ||
- VALUE: half | ||
- VALUE: float | ||
- VALUE: int | ||
- VALUE: int8 | ||
shader_variants: | ||
- NAME: buffer_to_nchw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
backends/vulkan/runtime/graph/ops/glsl/nchw_to_buffer.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#version 450 core | ||
|
||
#define PRECISION ${PRECISION} | ||
|
||
#define T ${buffer_scalar_type(DTYPE)} | ||
|
||
#include "indexing_utils.h" | ||
|
||
${define_required_extensions(DTYPE)} | ||
|
||
layout(std430) buffer; | ||
|
||
${layout_declare_tensor(0, "w", "t_out", DTYPE, STORAGE)} | ||
${layout_declare_tensor(1, "r", "nchw_in", DTYPE, STORAGE)} | ||
${layout_declare_ubo(2, "ivec4", "out_sizes")} | ||
${layout_declare_ubo(3, "ivec4", "out_strides")} | ||
${layout_declare_ubo(4, "int", "numel")} | ||
|
||
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in; | ||
|
||
// This constant is unused in this shader but is kept so that the signature is | ||
// consistent with nchw_to_image. | ||
layout(constant_id = 3) const int UNUSED_packed_dim = W_DIM; | ||
|
||
void main() { | ||
int out_id = int(gl_GlobalInvocationID.x); | ||
if (out_id >= numel) { | ||
return; | ||
} | ||
|
||
ivec4 out_idx = to_tensor_idx(out_id, out_strides); | ||
const int in_id = to_nchw_buffer_i(out_idx, out_sizes); | ||
|
||
t_out[out_id] = nchw_in[in_id]; | ||
} |
18 changes: 18 additions & 0 deletions
18
backends/vulkan/runtime/graph/ops/glsl/nchw_to_buffer.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
nchw_to_buffer: | ||
parameter_names_with_default_values: | ||
DTYPE: float | ||
STORAGE: buffer | ||
generate_variant_forall: | ||
DTYPE: | ||
- VALUE: half | ||
- VALUE: float | ||
- VALUE: int | ||
- VALUE: int8 | ||
shader_variants: | ||
- NAME: nchw_to_buffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters