Skip to content

aten.sin, aten.cos, aten.neg #3706

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
3 changes: 3 additions & 0 deletions backends/vulkan/partitioner/supported_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ def __contains__(self, op):
UNARY_OPS = [
exir_ops.edge.aten.abs.default,
exir_ops.edge.aten.clamp.default,
exir_ops.edge.aten.cos.default,
exir_ops.edge.aten.exp.default,
exir_ops.edge.aten.gelu.default,
exir_ops.edge.aten.hardshrink.default,
exir_ops.edge.aten.hardtanh.default,
exir_ops.edge.aten.neg.default,
exir_ops.edge.aten.relu.default,
exir_ops.edge.aten.sigmoid.default,
exir_ops.edge.aten.sin.default,
exir_ops.edge.aten.sqrt.default,
exir_ops.edge.aten.tanh.default,
]
Expand Down
6 changes: 6 additions & 0 deletions backends/vulkan/runtime/graph/ops/glsl/unary_op.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ unary_op:
- NAME: clamp_int
OPERATOR: clamp(X, A, B)
DTYPE: int
- NAME: cos
OPERATOR: cos(X)
- NAME: exp
OPERATOR: exp(X)
- NAME: gelu
OPERATOR: 0.5 * X * (1 + tanh(sqrt(2 / 3.141593) * (X + 0.044715 * X * X * X)))
- NAME: neg
OPERATOR: -X
- NAME: sigmoid
OPERATOR: 1 / (1 + exp(-1 * X))
- NAME: sin
OPERATOR: sin(X)
- NAME: sqrt
OPERATOR: sqrt(X)
- NAME: tanh
Expand Down
6 changes: 6 additions & 0 deletions backends/vulkan/runtime/graph/ops/impl/UnaryOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ void gelu(ComputeGraph& graph, const std::vector<ValueRef>& args) {
}

DEFINE_ACTIVATION_FN(abs);
DEFINE_ACTIVATION_FN(cos);
DEFINE_ACTIVATION_FN(exp);
DEFINE_ACTIVATION_FN(neg);
DEFINE_ACTIVATION_FN(sigmoid);
DEFINE_ACTIVATION_FN(sin);
DEFINE_ACTIVATION_FN(sqrt);
DEFINE_ACTIVATION_FN(tanh);
DEFINE_CLAMP_FN(clamp);
Expand All @@ -134,11 +137,14 @@ DEFINE_HARDSHRINK_FN(hardshrink);
REGISTER_OPERATORS {
VK_REGISTER_OP(aten.abs.default, abs);
VK_REGISTER_OP(aten.clamp.default, clamp);
VK_REGISTER_OP(aten.cos.default, cos);
VK_REGISTER_OP(aten.exp.default, exp);
VK_REGISTER_OP(aten.gelu.default, gelu);
VK_REGISTER_OP(aten.hardtanh.default, hardtanh);
VK_REGISTER_OP(aten.neg.default, neg);
VK_REGISTER_OP(aten.relu.default, relu);
VK_REGISTER_OP(aten.sigmoid.default, sigmoid);
VK_REGISTER_OP(aten.sin.default, sin);
VK_REGISTER_OP(aten.sqrt.default, sqrt);
VK_REGISTER_OP(aten.tanh.default, tanh);
VK_REGISTER_OP(aten.hardshrink.default, hardshrink);
Expand Down
3 changes: 3 additions & 0 deletions backends/vulkan/test/op_tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,4 +807,7 @@ def get_gelu_inputs():
"aten.gelu.default": get_gelu_inputs(),
"aten.hardshrink.default": get_unary_ops_inputs(),
"aten.upsample_nearest2d.vec": get_upsample_inputs(),
"aten.sin.default": get_unary_ops_inputs(),
"aten.neg.default": get_unary_ops_inputs(),
"aten.cos.default": get_unary_ops_inputs(),
}
4 changes: 2 additions & 2 deletions backends/vulkan/test/op_tests/utils/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ class GeneratedOpsTest_{op_name} : public ::testing::TestWithParam< ::std::tuple
protected:
ComputeGraph* graph;
at::ScalarType test_dtype = at::kFloat;
float rtol = 1e-5;
float atol = 1e-5;
float rtol = 1e-4;
float atol = 1e-4;

void SetUp() override {{
GraphConfig config;
Expand Down
30 changes: 30 additions & 0 deletions backends/vulkan/test/test_vulkan_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,16 @@ def forward(self, x):

self.lower_module_and_test_output(ClampModule(), sample_inputs)

def test_vulkan_backend_cos(self):
class CosModule(torch.nn.Module):
def __init__(self):
super().__init__()

def forward(self, x):
return torch.cos(x)

self.lower_unary_module_and_test_output(CosModule())

def test_vulkan_backend_hardtanh(self):
class HardTanHModule(torch.nn.Module):
def __init__(self):
Expand All @@ -414,6 +424,26 @@ def forward(self, x):

self.lower_unary_module_and_test_output(ExpModule())

def test_vulkan_backend_neg(self):
class NegModule(torch.nn.Module):
def __init__(self):
super().__init__()

def forward(self, x):
return torch.neg(x)

self.lower_unary_module_and_test_output(NegModule())

def test_vulkan_backend_sin(self):
class SinModule(torch.nn.Module):
def __init__(self):
super().__init__()

def forward(self, x):
return torch.sin(x)

self.lower_unary_module_and_test_output(SinModule())

def test_vulkan_backend_relu(self):
class ReLUModule(torch.nn.Module):
def __init__(self):
Expand Down