-
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.
Summary: Introduce a graph node to call vkcmdBlitImage which can convert between dtypes (and also perform scaling, filtering etc. but we don't need them right now). Differential Revision: D63839654
- Loading branch information
1 parent
8a32657
commit d82f981
Showing
6 changed files
with
163 additions
and
0 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
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,65 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include <executorch/backends/vulkan/runtime/graph/ops/BlitNode.h> | ||
|
||
#include <executorch/backends/vulkan/runtime/graph/ComputeGraph.h> | ||
|
||
namespace vkcompute { | ||
|
||
BlitNode::BlitNode( | ||
ComputeGraph& graph, | ||
ValueRef src, | ||
ValueRef dst, | ||
// const vkapi::ScalarType& dtype, | ||
const ResizeFunction& resize_fn, | ||
const std::vector<ValueRef>& resize_args) | ||
: ExecuteNode(resize_fn, resize_args, {}, "Blit Node"), | ||
src_(src), | ||
dst_(dst) { | ||
(void)graph; | ||
} | ||
|
||
void BlitNode::encode(ComputeGraph* graph) { | ||
auto src_tensor = graph->get_tensor(src_); | ||
auto dst_tensor = graph->get_tensor(dst_); | ||
VK_CHECK_COND( | ||
src_tensor->storage_type() != utils::kBuffer && | ||
dst_tensor->storage_type() != utils::kBuffer, | ||
"BlitNode: Only texture backed tensors are supported."); | ||
|
||
api::Context* const context = graph->context(); | ||
vkapi::PipelineBarrier pipeline_barrier{}; | ||
|
||
std::unique_lock<std::mutex> cmd_lock = context->dispatch_lock(); | ||
|
||
// Hack to get timing data for non shader op | ||
std::string kernel_name("Blit_"); | ||
kernel_name.reserve(32); | ||
kernel_name += vkapi::to_string(src_tensor->dtype()); | ||
kernel_name += "_to_"; | ||
kernel_name += vkapi::to_string(dst_tensor->dtype()); | ||
|
||
context->report_shader_dispatch_start( | ||
kernel_name, utils::uvec3(), utils::uvec3(), node_id_); | ||
|
||
context->register_blit( | ||
pipeline_barrier, | ||
src_tensor->image( | ||
pipeline_barrier, | ||
vkapi::PipelineStage::TRANSFER, | ||
vkapi::kRead), | ||
dst_tensor->image( | ||
pipeline_barrier, | ||
vkapi::PipelineStage::TRANSFER, | ||
vkapi::kWrite)); | ||
|
||
context->report_shader_dispatch_end(); | ||
} | ||
|
||
} // namespace vkcompute |
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,45 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <executorch/backends/vulkan/runtime/api/api.h> | ||
#include <executorch/backends/vulkan/runtime/graph/ComputeGraph.h> | ||
|
||
#include <executorch/backends/vulkan/runtime/graph/containers/Value.h> | ||
|
||
#include <executorch/backends/vulkan/runtime/graph/ops/ExecuteNode.h> | ||
|
||
namespace vkcompute { | ||
|
||
/* | ||
* Represents a tensor blit execution op in a ML model. | ||
*/ | ||
class BlitNode final : public ExecuteNode { | ||
friend class ComputeGraph; | ||
|
||
public: | ||
explicit BlitNode( | ||
ComputeGraph& graph, | ||
ValueRef src, | ||
ValueRef dst, | ||
/*const vkapi::ScalarType& dtype,*/ | ||
const ResizeFunction& resize_fn = nullptr, | ||
const std::vector<ValueRef>& resize_args = {}); | ||
|
||
~BlitNode() = default; | ||
|
||
void encode(ComputeGraph* graph) override; | ||
|
||
protected: | ||
ValueRef src_; | ||
ValueRef dst_; | ||
// const vkapi::ScalarType &dtype_; | ||
}; | ||
|
||
} // namespace vkcompute |
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