Skip to content
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

[Lang] [ir] [cuda] Add clz instruction #8276

Merged
merged 11 commits into from
Oct 31, 2023

Conversation

JettChenT
Copy link
Contributor

@JettChenT JettChenT commented Jul 11, 2023

Issue: #8212

Brief Summary

🤖 Generated by Copilot at 5d312ab

This pull request implements a new clz function in Taichi, which counts the number of leading zeros for a 32-bit integer. The function is available as a Python function decorator, a unary operation in the Taichi expression system, and a backend-specific intrinsic in the code generation. The pull request modifies the relevant files in the python, taichi, and codegen directories.

Walkthrough

🤖 Generated by Copilot at 5d312ab

  • Add a new function clz to count the number of leading zeros for a 32-bit integer (link, link, link, link, link)
  • Define the function clz in the ops module in python/taichi/lang/ops.py using a unary operation wrapper (link)
  • Add a wrapper function clz in the mathimpl module in python/taichi/math/mathimpl.py to allow using clz as a Taichi function decorator (link)
  • Add a new macro for the clz unary operation in taichi/inc/unary_op.inc.h and taichi/ir/expression_ops.h to expand to the corresponding enum value and expression class (link, link)
  • Add a new macro for the clz unary operation in taichi/python/export_lang.cpp to bind the operation to the Python interface (link)
  • Implement the clz unary operation for different backends (link, link, link)
    • Add a new case for the clz unary operation in the CUDA backend code generation in taichi/codegen/cuda/codegen_cuda.cpp, which calls the CUDA intrinsic function __clz and checks the input type (link)
    • Add a new case for the clz unary operation in the LLVM backend code generation in taichi/codegen/llvm/codegen_llvm.cpp, which calls the LLVM intrinsic function ctlz and assigns the result to the statement value (link)
    • Add a new case for the clz unary operation in the SPIRV backend code generation in taichi/codegen/spirv/spirv_codegen.cpp, which calls the GLSL 450 extended instruction FindMSB and subtracts the result from 32 (link)
  • Add a new method for the clz unary operation in the IR builder class, which is a helper class for constructing IR statements (link, link)
    • Add a declaration for the clz unary operation method in the IR builder class header file in taichi/ir/ir_builder.h (link)
    • Add a definition for the clz unary operation method in the IR builder class source file in taichi/ir/ir_builder.cpp, which creates and inserts a new unary operation statement with the clz type and the input value (link)

@netlify
Copy link

netlify bot commented Jul 11, 2023

Deploy Preview for docsite-preview ready!

Name Link
🔨 Latest commit de0ecd6
🔍 Latest deploy log https://app.netlify.com/sites/docsite-preview/deploys/654064c61249e50008547141
😎 Deploy Preview https://deploy-preview-8276--docsite-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@JettChenT JettChenT changed the title add clz instruction [Lang] [ir] [cuda] add clz instruction Jul 11, 2023
@JettChenT JettChenT changed the title [Lang] [ir] [cuda] add clz instruction [Lang] [ir] [cuda] Add clz instruction Aug 6, 2023
@JettChenT JettChenT marked this pull request as ready for review August 7, 2023 02:21
@JettChenT
Copy link
Contributor Author

Hi! I have added the respective operators and tests into taichi, though I am not quite sure regarding whether the failed tests are a result of my addition of the clz operator (one of them seems to be a git cloning issue). Any help would be much appreciated!

@lin-hitonami
Copy link
Contributor

/rebase

Copy link
Contributor

@lin-hitonami lin-hitonami left a comment

Choose a reason for hiding this comment

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

LGTM

@lin-hitonami
Copy link
Contributor

Thanks! Sorry for the late review.

@lin-hitonami lin-hitonami merged commit ac49f79 into taichi-dev:master Oct 31, 2023
28 checks passed
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.

3 participants