Skip to content

Conversation

@jikechao
Copy link

@jikechao jikechao commented Nov 7, 2025

PR Category

Operator

Type of Change

New Feature

Description

Support a new operator Tan

Progress

  • Change is properly reviewed (1 reviewer required, 2 recommended).
  • Change is fully covered by a UT.

Performance

Signed-off-by: Qingchao Shen <[email protected]>
Signed-off-by: Qingchao Shen <[email protected]>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jikechao, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the available mathematical operations by adding a new tan operator. The implementation leverages Triton's JIT capabilities to ensure efficient, dynamic pointwise computation of the tangent function, offering both a standard return and an in-place modification variant.

Highlights

  • New Operator Support: Introduced support for the tan (tangent) mathematical operator.
  • Triton Integration: Implemented the tan operator using Triton's JIT compilation for efficient, dynamic pointwise computation.
  • In-place Operation: Provided both out-of-place (tan) and in-place (tan_) versions of the tangent function.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the tan operator. The implementation is straightforward. I've suggested a simplification to use triton.language.tan directly, which should be more efficient and maintainable. As indicated in the pull request description, please remember to add unit tests for the new operator to ensure its correctness.

Added 'tan' and 'tan_' functions to the module exports.

Signed-off-by: Qingchao Shen <[email protected]>
Added tests for the tan and tan_ functions with accuracy checks.

Signed-off-by: Qingchao Shen <[email protected]>
@jikechao
Copy link
Author

jikechao commented Nov 7, 2025

@jikechao
Copy link
Author

@0x45f @kiddyjinjin @StrongSpoon @iclementine @zhzhcookie
Hi all, could you help me review this PR? It seems that the error in the CI test is not related to this PR.

@0x45f
Copy link
Collaborator

0x45f commented Nov 11, 2025

@0x45f @kiddyjinjin @StrongSpoon @iclementine @zhzhcookie Hi all, could you help me review this PR? It seems that the error in the CI test is not related to this PR.

please merge master to fix code-format-check ci and add benchmark result in Performance

@sgjzfzzf
Copy link
Collaborator

Thank you for your contribution! Could u please also put the performance report in the PR comment? It would be helpful to reviewers.

@jikechao
Copy link
Author

@0x45f @kiddyjinjin @StrongSpoon @iclementine @zhzhcookie Hi all, could you help me review this PR? It seems that the error in the CI test is not related to this PR.

please merge master to fix code-format-check ci and add benchmark result in Performance

@0x45f Thanks for your fixing. I have merged into the master branch

@jikechao
Copy link
Author

Thank you for your contribution! Could u please also put the performance report in the PR comment? It would be helpful to reviewers.

@sgjzfzzf Sure, I'll provide the performance comparison sooner.

@CLAassistant
Copy link

CLAassistant commented Nov 18, 2025

CLA assistant check
All committers have signed the CLA.

@jikechao
Copy link
Author

jikechao commented Nov 18, 2025

Operator: tan  Performance Test (dtype=torch.float16, mode=kernel,level=comprehensive)
Status       Torch Latency (ms)    Gems Latency (ms)         Gems Speedup               TFLOPS          Size Detail
--------------------------------------------------------------------------------------------------------------------
SUCCESS               5.644288            6.661120               0.847               0.161          [torch.Size([1073741824])]
SUCCESS               0.004096            0.005120               0.800               0.001          [torch.Size([64, 64])]
SUCCESS               0.086016            0.086016               1.000               0.195          [torch.Size([4096, 4096])]
SUCCESS               0.086016            0.084992               1.012               0.197          [torch.Size([64, 512, 512])]
SUCCESS               5.646336            6.397952               0.883               0.168          [torch.Size([1024, 1024, 1024])]
SUCCESS               0.005120            0.005120               1.000               0.000          [torch.Size([1024, 1])]
SUCCESS               0.005120            0.005120               1.000               0.003          [torch.Size([1024, 16])]
SUCCESS               0.006144            0.006144               1.000               0.043          [torch.Size([1024, 256])]
SUCCESS               0.025600            0.025600               1.000               0.164          [torch.Size([1024, 4096])]
SUCCESS               0.323584            0.330752               0.978               0.203          [torch.Size([1024, 65536])]
SUCCESS               0.004096            0.005120               0.800               0.001          [torch.Size([64, 64, 1])]
SUCCESS               0.005120            0.005120               1.000               0.013          [torch.Size([64, 64, 16])]
SUCCESS               0.009216            0.009216               1.000               0.114          [torch.Size([64, 64, 256])]
SUCCESS               0.086016            0.086016               1.000               0.195          [torch.Size([64, 64, 4096])]


Operator: tan  Performance Test (dtype=torch.float32, mode=kernel,level=comprehensive)
Status       Torch Latency (ms)    Gems Latency (ms)         Gems Speedup               TFLOPS          Size Detail
--------------------------------------------------------------------------------------------------------------------
SUCCESS              10.129408           10.323968               0.981               0.104          [torch.Size([1073741824])]
SUCCESS               0.005120            0.004096               1.250               0.001          [torch.Size([64, 64])]
SUCCESS               0.163840            0.164864               0.994               0.102          [torch.Size([4096, 4096])]
SUCCESS               0.163840            0.165888               0.988               0.101          [torch.Size([64, 512, 512])]
SUCCESS              10.122240           10.384384               0.975               0.103          [torch.Size([1024, 1024, 1024])]
SUCCESS               0.005120            0.005120               1.000               0.000          [torch.Size([1024, 1])]
SUCCESS               0.004096            0.005120               0.800               0.003          [torch.Size([1024, 16])]
SUCCESS               0.007168            0.007168               1.000               0.037          [torch.Size([1024, 256])]
SUCCESS               0.044032            0.045056               0.977               0.093          [torch.Size([1024, 4096])]
SUCCESS               0.641024            0.642048               0.998               0.105          [torch.Size([1024, 65536])]
SUCCESS               0.005120            0.004096               1.250               0.001          [torch.Size([64, 64, 1])]
SUCCESS               0.005120            0.005120               1.000               0.013          [torch.Size([64, 64, 16])]
SUCCESS               0.014336            0.014336               1.000               0.073          [torch.Size([64, 64, 256])]
SUCCESS               0.163840            0.165888               0.988               0.101          [torch.Size([64, 64, 4096])]


Operator: tan  Performance Test (dtype=torch.bfloat16, mode=kernel,level=comprehensive)
Status       Torch Latency (ms)    Gems Latency (ms)         Gems Speedup               TFLOPS          Size Detail
--------------------------------------------------------------------------------------------------------------------
SUCCESS               5.520384            6.246400               0.884               0.172          [torch.Size([1073741824])]
SUCCESS               0.004096            0.004096               1.000               0.001          [torch.Size([64, 64])]
SUCCESS               0.084992            0.086016               0.988               0.195          [torch.Size([4096, 4096])]
SUCCESS               0.084992            0.084992               1.000               0.197          [torch.Size([64, 512, 512])]
SUCCESS               5.441536            6.245376               0.871               0.172          [torch.Size([1024, 1024, 1024])]
SUCCESS               0.004096            0.004096               1.000               0.000          [torch.Size([1024, 1])]
SUCCESS               0.005120            0.005120               1.000               0.003          [torch.Size([1024, 16])]
SUCCESS               0.006144            0.006144               1.000               0.043          [torch.Size([1024, 256])]
SUCCESS               0.025600            0.025600               1.000               0.164          [torch.Size([1024, 4096])]
SUCCESS               0.323584            0.324608               0.997               0.207          [torch.Size([1024, 65536])]
SUCCESS               0.005120            0.004096               1.250               0.001          [torch.Size([64, 64, 1])]
SUCCESS               0.005120            0.005120               1.000               0.013          [torch.Size([64, 64, 16])]
SUCCESS               0.009216            0.010240               0.900               0.102          [torch.Size([64, 64, 256])]
SUCCESS               0.084992            0.086016               0.988               0.195          [torch.Size([64, 64, 4096])]

@jikechao
Copy link
Author

@sgjzfzzf @0x45f I have uploaded the performance results. Could you help me review it?

@0x45f 0x45f self-assigned this Nov 18, 2025
Signed-off-by: Qingchao Shen <[email protected]>
@jikechao
Copy link
Author

benchmark/test_unary_pointwise_perf.py
Operator: tan  Performance Test (dtype=torch.float16, mode=kernel,level=comprehensive)
Status       Torch Latency (ms)    Gems Latency (ms)         Gems Speedup               TFLOPS          Size Detail
--------------------------------------------------------------------------------------------------------------------
SUCCESS               5.746688            6.739968               0.853               0.159          [torch.Size([1073741824])]
SUCCESS               0.005120            0.004096               1.250               0.001          [torch.Size([64, 64])]
SUCCESS               0.084992            0.086016               0.988               0.195          [torch.Size([4096, 4096])]
SUCCESS               0.084992            0.086016               0.988               0.195          [torch.Size([64, 512, 512])]
SUCCESS               5.646336            5.809152               0.972               0.185          [torch.Size([1024, 1024, 1024])]
SUCCESS               0.005120            0.005120               1.000               0.000          [torch.Size([1024, 1])]
SUCCESS               0.004096            0.005120               0.800               0.003          [torch.Size([1024, 16])]
SUCCESS               0.006112            0.006144               0.995               0.043          [torch.Size([1024, 256])]
SUCCESS               0.025600            0.025600               1.000               0.164          [torch.Size([1024, 4096])]
SUCCESS               0.323584            0.324608               0.997               0.207          [torch.Size([1024, 65536])]
SUCCESS               0.004096            0.004096               1.000               0.001          [torch.Size([64, 64, 1])]
SUCCESS               0.005120            0.005120               1.000               0.013          [torch.Size([64, 64, 16])]
SUCCESS               0.009216            0.010240               0.900               0.102          [torch.Size([64, 64, 256])]
SUCCESS               0.084992            0.084992               1.000               0.197          [torch.Size([64, 64, 4096])]


Operator: tan  Performance Test (dtype=torch.float32, mode=kernel,level=comprehensive)
Status       Torch Latency (ms)    Gems Latency (ms)         Gems Speedup               TFLOPS          Size Detail
--------------------------------------------------------------------------------------------------------------------
SUCCESS              10.116096           10.195968               0.992               0.105          [torch.Size([1073741824])]
SUCCESS               0.005120            0.005120               1.000               0.001          [torch.Size([64, 64])]
SUCCESS               0.163840            0.164864               0.994               0.102          [torch.Size([4096, 4096])]
SUCCESS               0.163840            0.164864               0.994               0.102          [torch.Size([64, 512, 512])]
SUCCESS              10.507264           10.196992               1.030               0.105          [torch.Size([1024, 1024, 1024])]
SUCCESS               0.005120            0.004096               1.250               0.000          [torch.Size([1024, 1])]
SUCCESS               0.005120            0.004096               1.250               0.004          [torch.Size([1024, 16])]
SUCCESS               0.007168            0.007168               1.000               0.037          [torch.Size([1024, 256])]
SUCCESS               0.044032            0.044032               1.000               0.095          [torch.Size([1024, 4096])]
SUCCESS               0.641024            0.640000               1.002               0.105          [torch.Size([1024, 65536])]
SUCCESS               0.005120            0.005120               1.000               0.001          [torch.Size([64, 64, 1])]
SUCCESS               0.005120            0.005120               1.000               0.013          [torch.Size([64, 64, 16])]
SUCCESS               0.014336            0.014336               1.000               0.073          [torch.Size([64, 64, 256])]
SUCCESS               0.169984            0.165888               1.025               0.101          [torch.Size([64, 64, 4096])]


Operator: tan  Performance Test (dtype=torch.bfloat16, mode=kernel,level=comprehensive)
Status       Torch Latency (ms)    Gems Latency (ms)         Gems Speedup               TFLOPS          Size Detail
--------------------------------------------------------------------------------------------------------------------
SUCCESS               5.439488            5.735424               0.948               0.187          [torch.Size([1073741824])]
SUCCESS               0.004096            0.005120               0.800               0.001          [torch.Size([64, 64])]
SUCCESS               0.084992            0.084992               1.000               0.197          [torch.Size([4096, 4096])]
SUCCESS               0.084992            0.084992               1.000               0.197          [torch.Size([64, 512, 512])]
SUCCESS               5.441536            5.733376               0.949               0.187          [torch.Size([1024, 1024, 1024])]
SUCCESS               0.005120            0.005120               1.000               0.000          [torch.Size([1024, 1])]
SUCCESS               0.005120            0.004096               1.250               0.004          [torch.Size([1024, 16])]
SUCCESS               0.006144            0.006144               1.000               0.043          [torch.Size([1024, 256])]
SUCCESS               0.025600            0.024576               1.042               0.171          [torch.Size([1024, 4096])]
SUCCESS               0.323584            0.324608               0.997               0.207          [torch.Size([1024, 65536])]
SUCCESS               0.004096            0.004096               1.000               0.001          [torch.Size([64, 64, 1])]
SUCCESS               0.005120            0.005120               1.000               0.013          [torch.Size([64, 64, 16])]
SUCCESS               0.009216            0.009216               1.000               0.114          [torch.Size([64, 64, 256])]
SUCCESS               0.084992            0.084992               1.000               0.197          [torch.Size([64, 64, 4096])]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants