Skip to content

Move graph runtime from PT directory to ET directory #2086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backends/vulkan/runtime/VulkanBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/

#include <ATen/native/vulkan/graph/Graph.h>
#include <ATen/native/vulkan/graph/OperatorRegistry.h>
#include <executorch/backends/vulkan/runtime/graph/Graph.h>
#include <executorch/backends/vulkan/runtime/graph/OperatorRegistry.h>

#include <executorch/backends/vulkan/runtime/VulkanDelegateHeader.h>
#include <executorch/backends/vulkan/schema_generated.h>
Expand Down
27 changes: 27 additions & 0 deletions backends/vulkan/runtime/graph/Config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Context.h>

namespace at {
namespace native {
namespace vulkan {

struct GraphConfig final {
api::ContextConfig contextConfig;
};

} // namespace vulkan
} // namespace native
} // namespace at

#endif /* USE_VULKAN_API */
29 changes: 29 additions & 0 deletions backends/vulkan/runtime/graph/Constant.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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/Constant.h>

namespace at {
namespace native {
namespace vulkan {

TensorRef::TensorRef(
const std::vector<int64_t>& t_sizes,
api::ScalarType t_dtype,
const void* const t_data)
: sizes{}, dtype{t_dtype}, data{t_data} {
size_t ndim = t_sizes.size();
sizes.resize(ndim);
for (int i = 0; i < ndim; ++i) {
sizes[i] = t_sizes.at(i);
}
}

} // namespace vulkan
} // namespace native
} // namespace at
45 changes: 45 additions & 0 deletions backends/vulkan/runtime/graph/Constant.h
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

#ifdef USE_VULKAN_API

#include <ATen/native/vulkan/api/Context.h>

namespace at {
namespace native {
namespace vulkan {

/*
* Represents a reference to a tensor that has been serialized with the model,
* such as a serialized weight tensor. It contains some metadata as well as a
* raw pointer to the data of the tensor, which is assumed to be contiguous.
*/
struct TensorRef final {
std::vector<int64_t> sizes;
api::ScalarType dtype;
const void* data;

explicit TensorRef(
const std::vector<int64_t>& t_sizes,
api::ScalarType t_dtype,
const void* const t_data);

TensorRef(const TensorRef&) = default;
TensorRef& operator=(const TensorRef&) = default;

TensorRef(TensorRef&&) = default;
TensorRef& operator=(TensorRef&&) = default;
};

} // namespace vulkan
} // namespace native
} // namespace at

#endif /* USE_VULKAN_API */
40 changes: 40 additions & 0 deletions backends/vulkan/runtime/graph/Functions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 <ATen/native/vulkan/impl/Arithmetic.h>
#include <ATen/native/vulkan/impl/Common.h>

#include <executorch/backends/vulkan/runtime/graph/Functions.h>

#include <executorch/backends/vulkan/runtime/graph/ops/Arithmetic.h>

namespace at {
namespace native {
namespace vulkan {

#define DEFINE_ARITHMETIC_FN(function, op_type) \
ValueRef function(ComputeGraph& graph, const std::vector<ValueRef>& args) { \
return add_arithmetic_node( \
graph, \
args[0], \
args[1], \
args[2], \
arithmetic::OpType::op_type, \
args[3]); \
}

DEFINE_ARITHMETIC_FN(add, ADD);
DEFINE_ARITHMETIC_FN(sub, SUB);
DEFINE_ARITHMETIC_FN(mul, MUL);
DEFINE_ARITHMETIC_FN(div, DIV);
DEFINE_ARITHMETIC_FN(floor_div, FLOOR_DIV);
DEFINE_ARITHMETIC_FN(pow, POW);

} // namespace vulkan
} // namespace native
} // namespace at
33 changes: 33 additions & 0 deletions backends/vulkan/runtime/graph/Functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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

#ifdef USE_VULKAN_API

#include <executorch/backends/vulkan/runtime/graph/Graph.h>

namespace at {
namespace native {
namespace vulkan {

#define DEFINE_OP_FN(name) \
ValueRef name(ComputeGraph& graph, const std::vector<ValueRef>& args);

DEFINE_OP_FN(add);
DEFINE_OP_FN(sub);
DEFINE_OP_FN(mul);
DEFINE_OP_FN(div);
DEFINE_OP_FN(floor_div);
DEFINE_OP_FN(pow);

} // namespace vulkan
} // namespace native
} // namespace at

#endif /* USE_VULKAN_API */
Loading