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

feat: bitwise-ops-for-tensors #2498

Merged
merged 18 commits into from
Jan 24, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into feat/bitwise-ops
quinton11 committed Jan 11, 2025
commit 8cec801f42b00908e5a47ec26f61a50bb020540f
41 changes: 38 additions & 3 deletions crates/burn-jit/src/kernel/binary.rs
Original file line number Diff line number Diff line change
@@ -24,12 +24,45 @@ pub(crate) struct SubOp;
pub(crate) struct MulOp;
pub(crate) struct DivOp;
pub(crate) struct RemainderOp;
pub(crate) struct PowOp;
pub(crate) struct BitwiseAndOp;
pub(crate) struct BitwiseOrOp;
pub(crate) struct BitwiseXorOp;
pub(crate) struct BitwiseNotOp;

/// Since Powf only works on float, but we still want to implement the numeric binary op family, we
/// set another precision in the family type to cast, when necessary, the input value to a valid
/// float.
///
/// Because of this we won't benefit from the cubecl rust compilation speed improvement from using
/// the family pattern for [PowOp], but at least we don't duplicate code.
pub(crate) struct PowOp<F: Float> {
_f: PhantomData<F>,
}

impl BinaryOpFamily for AddOp {
type BinaryOp<C: Numeric> = Self;
}

impl BinaryOpFamily for SubOp {
type BinaryOp<C: Numeric> = Self;
}

impl BinaryOpFamily for MulOp {
type BinaryOp<C: Numeric> = Self;
}

impl BinaryOpFamily for DivOp {
type BinaryOp<C: Numeric> = Self;
}

impl BinaryOpFamily for RemainderOp {
type BinaryOp<C: Numeric> = Self;
}

impl<F: Float> BinaryOpFamily for PowOp<F> {
type BinaryOp<C: Numeric> = Self;
}

#[cube]
impl<N: Numeric> BinaryOp<N> for AddOp {
fn execute(lhs: Line<N>, rhs: Line<N>) -> Line<N> {
@@ -76,6 +109,7 @@ impl<N: Numeric, F: Float> BinaryOp<N> for PowOp<F> {
}
}


#[cube]
impl<N: Numeric> BinaryOp<N> for BitwiseAndOp {
fn execute(lhs: Line<N>, rhs: Line<N>) -> Line<N> {
@@ -105,8 +139,9 @@ impl<N: Numeric> BinaryOp<N> for BitwiseNotOp {
}
}

#[cube(launch)]
pub(crate) fn kernel_scalar_binop<C: Numeric, O: BinaryOp<C>>(

#[cube(launch_unchecked)]
pub(crate) fn kernel_scalar_binop<C: Numeric, O: BinaryOpFamily>(
input: &Tensor<Line<C>>,
scalar: C,
output: &mut Tensor<Line<C>>,
You are viewing a condensed version of this merge commit. You can view the full changes here.