-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Add support for TRUNC unary operator (CPU +SYCL) #16032
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
base: master
Are you sure you want to change the base?
Conversation
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.
It might be better to consolidate all new unary ops PRs that are submitted recently into 2 PRs:
- One with CPU-only implementation
- One with SYCL implementation
The SYCL should be reviewed by @NeoZhangJianyu or someone else on the Intel team (not sure who is active these days).
|
||
for (const std::string& btype : {"f16", "f32", "q8_1"}) { | ||
std::vector<std::string> btypes = {"f16", "f32"}; | ||
|
||
#if defined(GGML_VULKAN_INTEGER_DOT_GLSLC_SUPPORT) | ||
btypes.push_back("q8_1"); | ||
#endif | ||
|
||
for (const std::string& btype : btypes) { | ||
for (const auto& tname : type_names) { |
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.
This change should be in a separate PR
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.
This is my code from #15740, no idea what it is doing here.
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.
I don't understand what needs fixing
This is not a change I made
I would appreciate a clearer explanation
thanks
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.
The change is in 75faa5a for whatever reason, it should not be a part of that commit.
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.
I fixed it.
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.
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.
Be careful not to add extra files that are not used in the project.
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.
Thanks for the review!
This has been fixed.
ggml/src/ggml.c
Outdated
|
||
static const char * GGML_UNARY_OP_NAME[GGML_UNARY_OP_COUNT] = { | ||
"ABS", | ||
"ROUND", |
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.
"ROUND", | |
"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.
The error has been corrected.
ggml/include/ggml.h
Outdated
|
||
enum ggml_unary_op { | ||
GGML_UNARY_OP_ABS, | ||
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.
Add new unary ops at the end of the enum.
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.
Thanks for the review
This will be fixed soon
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.
This has been fixed.
This PR introduces the TRUNC unary operator, applying element-wise truncation (truncf / sycl::trunc) on tensors.
Changes:
CPU (ggml-cpu.c)
Added forward implementation: ggml_compute_forward_trunc
Registered op in scheduler: ggml_get_n_tasks
SYCL (ggml-sycl)
Added device function: op_trunc
Added kernel: unary_op_trunc_kernel
Added dispatch wrapper: ggml_sycl_op_trunc
Exposed API: ggml_sycl_trunc
Tests
Included in backend coverage tests
Support matrix can be regenerated:
./build/bin/test-backend-ops support -o TRUNC --output csv > trunc_support.csv
./scripts/create_ops_docs.py
Produces trunc_support.csv verifying backend availability.
Notes
Implemented for F32 (and F16 where SYCL supports it)
Brings consistency with existing unary ops