-
-
Notifications
You must be signed in to change notification settings - Fork 104
Add comparison tensor operations #386
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
Some things to consider and choices I would like feedback on:
|
It should be fine not to. I added these struct parameters to the binary operations in #346 only because of huber_error's delta parameter, and comparison operations should not have this kind of parameter. You should probably implement unary versions of these operations, because this is consistent with the rest of the api and will probably be the more common use case. While tensors of booleans are currently useless with the rest of the api, I think it is best to keep the output as tensors of booleans and to create operations for them. These could include inversion ( |
I don't understand how comparison could be unary. Did you mean something like comparing to a scalar? Or perhaps you meant that the comparison functions should be methods on the tensor type? (They are.) |
Sorry for the confusion, I meant that you should add operations that act like ScalarAdd, comparing each value within the tensor with a single number, like |
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 great start! I like the addition of CmpKernel/CmpOpCpuKernel/CmpOpCudaKernel for reducing code. Since you added the above and the actual kernel implementations look pretty small, I think combining them into the same file so the structure is the same as the other ops should be good:
- tensor_ops/
- cmp/
- mod.rs
- cuda_kernels.rs
- cpu_kernels.rs
- cmp.cu
where they would contain the following:
- mod.rs - all the tensor methods/functions & tests
- cpu_kernels.rs
- The trait definition for CmpOpCpuKernel
- The trait impl for
impl<Op: CmpOpCpuKernel<E>, E: Unit> CmpKernel<Op, E> for Cpu {
- all the
impl CmpOpCpuKernel<E> for EqKernelOp
for all the ops (Eq/Lt, etc)
- cuda_kernels.rs - similar to cpu kernels but for the cuda stuff
- cmp.cu all the forward functions for each op
I added the rest of the comparison operations as well as scalar operations. I was unsure about what to name the scalar comparisons, but I went with I was wondering whether I should also implement |
The |
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 looks great! Structure is perfect, and a lot of good stuff in here. Only a couple things to add and then its good to go 🚀
Please note that the CUDA code relies on If you try compiling this branch with |
} | ||
|
||
#[test] | ||
#[should_panic] |
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.
Nice test 😀
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.
Will merge once cudarc releases support for bools
Thanks for the contribution! |
Works towards #306.
Depends on coreylowman/cudarc#60.
I am creating this as a draft to get feedback on the structure before implementing other operations (although this should be quite straightforward now).
Let me know what you think.
I will add documentation once implementation is finalized.