-
Notifications
You must be signed in to change notification settings - Fork 13.4k
CPU: Add support for FLOOR,CEIL,ROUND and TRUNC unary operators #16083
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
Conversation
- Added the operators to unary op enum - Implemented API functions - Implemented forward and unary-op logic in CPU backend - Updated ggml_get_n_tasks - Updated operators names array and static_assert - Updated docs and enabled automatic tests
|
||
//ggml_trunc | ||
|
||
struct ggml_tensor * ggml_trunc( |
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.
IMO the naming trunc
is quite vast and can be misinterpreted as truncating only N fractional decimals. Naming like torch.frac
or python's modf()
makes more sense.
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.
Thank you for your feedback!
I have added documentation above the ggml_trunc and ggml_trunc_inplace functions in ggml.h to clarify their behavior (they truncate the fractional part towards zero, similar to std::trunc).
Please let me know if further clarification is needed.
Can merge after fixing the EditorConfig CI |
This looks ready for merge after rebase, forgotten? |
@safranowith gentle ping |
@safranowith I don't think that merge went exactly as planned. :) |
.All merge conflict markers have been cleaned up and the files are now
updated
.Let me know if the PR is now ready to be merge
בתאריך יום ד׳, 15 באוק׳ 2025 ב-12:13 מאת Sigbjørn Skjæret <
***@***.***>:
… *CISC* left a comment (ggml-org/llama.cpp#16083)
<#16083 (comment)>
@safranowith <https://github.com/safranowith> I don't think that merge
went exactly as planned. :)
—
Reply to this email directly, view it on GitHub
<#16083 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BT72BRJUJ36HM6CBLDENRID3XYF3NAVCNFSM6AAAAACG3UARIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMBVGM3TSOBTHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
A few more artifacts left to fix. |
.Thanks for the feedback! I've applied the suggested changes
.Please let me know if everything looks good now and if this is ready to be
merged
בתאריך יום ד׳, 15 באוק׳ 2025 ב-12:48 מאת Sigbjørn Skjæret <
***@***.***>:
… *CISC* left a comment (ggml-org/llama.cpp#16083)
<#16083 (comment)>
.All merge conflict markers have been cleaned up and the files are now
updated .Let me know if the PR is now ready to be merge
A few more artifacts left to fix.
—
Reply to this email directly, view it on GitHub
<#16083 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BT72BRM6Z2PLYGN7RHOZLOL3XYJ67AVCNFSM6AAAAACG3UARIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMBVGUZTKNZQGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
All good now, thank you, will merge once CI is done. |
GGML_UNARY_OP_FLOOR, | ||
GGML_UNARY_OP_CEIL, | ||
GGML_UNARY_OP_ROUND, | ||
GGML_UNARY_OP_TRUNC, |
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.
looks like a rebase artifact
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.
These lines are not a rebase artifact – they are newly introduced unary ops that don't exist in master
.
Confirmed via git diff master -- ggml/include/ggml.h
.
ggml/src/ggml-cpu/ops.cpp
Outdated
} | ||
} | ||
|
||
template<typename src_t, typename dst_t> |
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.
same
Thanks again for the review and approvals!
I noticed that some CI checks are failing.
Just to confirm — are those failures related to my changes, or unrelated?
בתאריך יום ד׳, 15 באוק׳ 2025 ב-15:54 מאת Sigbjørn Skjæret <
***@***.***>:
… *CISC* left a comment (ggml-org/llama.cpp#16083)
<#16083 (comment)>
.Thanks for the feedback! I've applied the suggested changes .Please let
me know if everything looks good now and if this is ready to be merged
All good now, thank you, will merge once CI is done.
—
Reply to this email directly, view it on GitHub
<#16083 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BT72BRLAPWZGNJFNGEDAKZL3XY7W7AVCNFSM6AAAAACG3UARIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMBWGI4TCNRYGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Let me know if there's anything I should address.
בתאריך יום ד׳, 15 באוק׳ 2025 ב-16:46 מאת ש.שפרנוביץ ***@***.***
>:
… Thanks again for the review and approvals!
I noticed that some CI checks are failing.
Just to confirm — are those failures related to my changes, or unrelated?
בתאריך יום ד׳, 15 באוק׳ 2025 ב-15:54 מאת Sigbjørn Skjæret <
***@***.***>:
> *CISC* left a comment (ggml-org/llama.cpp#16083)
> <#16083 (comment)>
>
> .Thanks for the feedback! I've applied the suggested changes .Please let
> me know if everything looks good now and if this is ready to be merged
>
> All good now, thank you, will merge once CI is done.
>
> —
> Reply to this email directly, view it on GitHub
> <#16083 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/BT72BRLAPWZGNJFNGEDAKZL3XY7W7AVCNFSM6AAAAACG3UARIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMBWGI4TCNRYGU>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
Unrelated. |
Thanks!
Now that the CPU implementation is approved and merged, I’ll continue with
supporting these operators in other backends (e.g. CUDA, SYCL).
Let me know if you have any guidance or preferences regarding that
direction.
בתאריך יום ד׳, 15 באוק׳ 2025 ב-22:25 מאת Sigbjørn Skjæret <
***@***.***>:
… Merged #16083 <#16083> into
master.
—
Reply to this email directly, view it on GitHub
<#16083 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/BT72BRJQAQWS3K33LTNCDLD3X2NSBAVCNFSM6AAAAACG3UARIKVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMRQGMYDGOBQGY3TCMQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Add new unary operators: FLOOR, CEIL, ROUND and TRUNC.
This PR adds support for the GGML_UNARY_OP_FLOOR, GGML_UNARY_OP_CEIL, GGML_UNARY_OP_ROUND and GGML_UNARY_OP_TRUNC operators to the GGML library.
Summary of changes:
Extended the ggml_unary_op enum and updated related arrays and assertions.
Implemented the corresponding API functions and integrated them into the codebase.
Ensured full compatibility with the existing unary operator infrastructure.
Testing:
All existing automated tests pass successfully.
Motivation:
These additions expand the mathematical capabilities of GGML, allowing users to efficiently perform operations related to decimal point manipulation—such as rounding up, down, or truncating the fractional part—on tensors.