forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use compile-time promotion to reduce bitwise op size & build time (py…
…torch#3487) Summary: Finally getting close to the end of compile-time promotion for Tensor ops! Differential Revision: D56855548
- Loading branch information
1 parent
5deeaf8
commit 29a4615
Showing
7 changed files
with
152 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <executorch/kernels/portable/cpu/util/broadcast_util.h> | ||
#include <executorch/runtime/kernel/kernel_includes.h> | ||
|
||
namespace torch { | ||
namespace executor { | ||
namespace native { | ||
namespace internal { | ||
|
||
template < | ||
bool can_cast, | ||
template <typename> | ||
typename OpFunc, | ||
typename CTYPE_A, | ||
typename CTYPE_B, | ||
typename CTYPE_IN, | ||
typename CTYPE_OUT> | ||
struct BitwiseOpInner; | ||
|
||
template < | ||
template <typename> | ||
typename OpFunc, | ||
typename CTYPE_A, | ||
typename CTYPE_B, | ||
typename CTYPE_IN, | ||
typename CTYPE_OUT> | ||
struct BitwiseOpInner<true, OpFunc, CTYPE_A, CTYPE_B, CTYPE_IN, CTYPE_OUT> { | ||
static void run(const Tensor& a, const Tensor& b, Tensor& out) { | ||
apply_binary_elementwise_fn<CTYPE_A, CTYPE_B, CTYPE_OUT>( | ||
// NOLINTNEXTLINE(facebook-hte-ConstantArgumentPassByValue) | ||
[](const CTYPE_A val_a, const CTYPE_B val_b) { | ||
CTYPE_IN a_casted = static_cast<CTYPE_IN>(val_a); | ||
CTYPE_IN b_casted = static_cast<CTYPE_IN>(val_b); | ||
CTYPE_IN value = OpFunc<CTYPE_IN>()(a_casted, b_casted); | ||
|
||
return static_cast<CTYPE_OUT>(value); | ||
}, | ||
a, | ||
b, | ||
out); | ||
} | ||
}; | ||
|
||
struct ReportCanCastBug { | ||
static void run(const Tensor&, const Tensor&, Tensor&) { | ||
ET_DCHECK_MSG(false, "BUG: canCast should have been checked above"); | ||
} | ||
}; | ||
|
||
template < | ||
template <typename> | ||
typename OpFunc, | ||
typename CTYPE_A, | ||
typename CTYPE_B, | ||
typename CTYPE_IN, | ||
typename CTYPE_OUT> | ||
struct BitwiseOpInner<false, OpFunc, CTYPE_A, CTYPE_B, CTYPE_IN, CTYPE_OUT> | ||
: public ReportCanCastBug {}; | ||
|
||
} // namespace internal | ||
} // namespace native | ||
} // namespace executor | ||
} // namespace torch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.