-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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] Add popcnt to llvm intrinsic support #7772
Conversation
✅ Deploy Preview for docsite-preview ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
9e83e6a
to
135b225
Compare
@ailzhang would you please have a look what is going on, if I use
using uint64 as popcnt type, then I pass to cuda backend for compute, then assert like the picture mentioned. |
@lgyStoic the error message indicates that you're passing a pointer to u64 to a function requires a pointer to i64. you'll need to use |
[pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci fix: add test api for popcnt
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
c2f7207
to
5c535b1
Compare
At last, found beause return type of popcll is i32, but in statement return type pointer is to u64 point, so the print function was crash.... at first, I was thinking there is some problem on call 'popcll' function.. |
/rebase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
[pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci fix: add test api for popcnt Issue: taichi-dev#7541 ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 9893837</samp> Added a new `popcnt` function to count the number of bits set to 1 in an integer, both for Python and Taichi expressions. Implemented the function in the `taichi.lang.ops` and `taichi.math` modules, and the CUDA and LLVM backends. Added tests and documentation for the function. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 9893837</samp> * Add a new function `popcnt` to the `taichi.lang.ops` module that returns the number of bits set to 1 in an integer ([link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-059028cb0798284bed05638becbc32d256736846de19746e196fe5f5ee7fd061R532-R538), [link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-059028cb0798284bed05638becbc32d256736846de19746e196fe5f5ee7fd061L1400-R1409)) * Import and wrap the `popcnt` function in the `taichi.math.mathimpl` module to support both Taichi expressions and Python scalars ([link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-5b3923516b48467202850afb384ef9901ecefae0173f03bcc9055adffe96d738L12-R12), [link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-5b3923516b48467202850afb384ef9901ecefae0173f03bcc9055adffe96d738R749-R753), [link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-5b3923516b48467202850afb384ef9901ecefae0173f03bcc9055adffe96d738L754-R759)) * Add the `popcnt` operation to the `UnaryOpType` enum class and the expression macros in the `taichi.inc.unary_op.inc.h` and `taichi.ir.expression_ops.h` files ([link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-f95015864ea3251da5d376f2a11e8f5a0045d7aaf4602370471686f56561dafdR21), [link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-b0b26408cd63f0a7edc6e9a6936ec09df7dc5f37c2ab65d72b3f9125f1385ba1R89)) * Add the `popcnt` operation to the `UNARY_STD` functions in the `taichi.codegen.cuda.codegen_cuda.cpp` and `taichi.codegen.llvm.codegen_llvm.cpp` files, which handle the code generation for unary operations on the CUDA and LLVM backends ([link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-50537ad5ea3b900c0d55a088f3cc285986340ad68c9b96fea481187c4dce49eaR270-R277), [link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-3c663c78745adcd3f6a7ac81fe99e628decc3040f292ea1e20ecd4b85a7f4313R209-R212)) * Add a temporary workaround for creating a `UnaryOpStmt` with the `popcnt` operation using a `BinaryOpStmt` with the `min` operation in the `IRBuilder` class in the `taichi.ir.ir_builder.cpp` and `taichi.ir.ir_builder.h` files ([link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-bdb4f85a29d6478a4482d81ca072237534fb641b52f3c529aca93e872ade6fecR341-R344), [link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-1894085b261e833e3e66924fc5b1cf63b9dd8b8aa0b3e78ec64366396131470dR196)) * Export the `popcnt` function to the Python module `taichi.lang.expr` using the `DEFINE_EXPRESSION_OP` macro in the `taichi.python.export_lang.cpp` file ([link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-af631a0c71978fe591e17005f01f7c06bc30ae36c65df306bbb3b08ade770167R887)) * Add the `popcnt` function to the list of math functions that are tested for consistency between Taichi expressions and Python scalars in the `tests.python.test_api.py` file ([link](https://github.com/taichi-dev/taichi/pull/7772/files?diff=unified&w=0#diff-3509125c0fe3c95de660001069a4006253de3ea41bba2989b839177d825e8879L107-R107)) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Haidong Lan <[email protected]>
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
fix: add test api for popcnt
Issue: #7541
Brief Summary
🤖 Generated by Copilot at 9893837
Added a new
popcnt
function to count the number of bits set to 1 in an integer, both for Python and Taichi expressions. Implemented the function in thetaichi.lang.ops
andtaichi.math
modules, and the CUDA and LLVM backends. Added tests and documentation for the function.Walkthrough
🤖 Generated by Copilot at 9893837
popcnt
to thetaichi.lang.ops
module that returns the number of bits set to 1 in an integer (link, link)popcnt
function in thetaichi.math.mathimpl
module to support both Taichi expressions and Python scalars (link, link, link)popcnt
operation to theUnaryOpType
enum class and the expression macros in thetaichi.inc.unary_op.inc.h
andtaichi.ir.expression_ops.h
files (link, link)popcnt
operation to theUNARY_STD
functions in thetaichi.codegen.cuda.codegen_cuda.cpp
andtaichi.codegen.llvm.codegen_llvm.cpp
files, which handle the code generation for unary operations on the CUDA and LLVM backends (link, link)UnaryOpStmt
with thepopcnt
operation using aBinaryOpStmt
with themin
operation in theIRBuilder
class in thetaichi.ir.ir_builder.cpp
andtaichi.ir.ir_builder.h
files (link, link)popcnt
function to the Python moduletaichi.lang.expr
using theDEFINE_EXPRESSION_OP
macro in thetaichi.python.export_lang.cpp
file (link)popcnt
function to the list of math functions that are tested for consistency between Taichi expressions and Python scalars in thetests.python.test_api.py
file (link)