Skip to content
Open
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
50 changes: 50 additions & 0 deletions backends/vulkan/test/custom_ops/impl/TestLinear.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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/OperatorRegistry.h>

#include <executorch/backends/vulkan/runtime/graph/ops/impl/Common.h>
#include <executorch/backends/vulkan/runtime/graph/ops/impl/MatMul.h>
#include <executorch/backends/vulkan/runtime/graph/ops/impl/Staging.h>

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

namespace vkcompute {

// Implementation selector values:
// 0 = default (use standard aten.linear.default dispatch)
// 1 = alternative path (also uses aten.linear.default for correctness)

void test_fp_linear(
ComputeGraph& graph,
const std::vector<ValueRef>& args) {
int32_t idx = 0;
const ValueRef input = args.at(idx++);
const ValueRef weight_data = args.at(idx++);
const ValueRef bias_data = args.at(idx++);
const ValueRef impl_selector_ref = args.at(idx++);
const ValueRef output = args.at(idx++);

// Extract the impl_selector flag
int32_t impl_selector = graph.extract_scalar<int32_t>(impl_selector_ref);

if (impl_selector == 0 || impl_selector == 1) {
// Both paths use the standard linear operator dispatch
// impl_selector=1 is provided as a hook for future alternative implementations
std::vector<ValueRef> linear_args = {input, weight_data, bias_data, output};
VK_GET_OP_FN("aten.linear.default")(graph, linear_args);
} else {
VK_THROW("Invalid impl_selector value: ", impl_selector);
}
}

REGISTER_OPERATORS {
VK_REGISTER_OP(test_etvk.test_fp_linear.default, test_fp_linear);
}

} // namespace vkcompute
2 changes: 2 additions & 0 deletions backends/vulkan/test/custom_ops/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ def define_common_targets(is_fbcode = False):
define_custom_op_test_binary("test_q8ta_conv2d")
define_custom_op_test_binary("test_q8ta_conv2d_pw")
define_custom_op_test_binary("test_q8ta_conv2d_dw")
define_custom_op_test_binary("q8ta_q8ta_q8to_add")
define_custom_op_test_binary("test_fp_linear")
Loading
Loading