Skip to content

Commit 54e13b2

Browse files
committed
Save some size in dtype_util when dtype selective build is not in use
We duplicate a lot of functions depending on the operator name so that dtype selective build will work. We can just detect if dtype selective build is in use and, if not, stop duplicating. Test Plan: Saves 28288 bytes of text in size_test_all_optimized_ops compared to previous PR on my Mac. ghstack-source-id: 2edc60c ghstack-comment-id: 2761913331 Pull-Request-resolved: pytorch/executorch#9742 ghstack-source-id: 2edc60c ghstack-comment-id: 2771183226 Pull Request resolved: pytorch/executorch#9829
1 parent ca76e66 commit 54e13b2

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

kernels/portable/cpu/util/dtype_util.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ enum class SupportedTensorDtypes {
228228
namespace internal {
229229

230230
template <typename CTYPE_COMPUTE, const char* op_name>
231-
load_to_compute_fn<CTYPE_COMPUTE> get_load_to_compute_fn(
231+
load_to_compute_fn<CTYPE_COMPUTE> get_load_to_compute_fn_impl(
232232
const Tensor& t,
233233
SupportedTensorDtypes dtypes) {
234234
switch (dtypes) {
@@ -252,7 +252,7 @@ load_to_compute_fn<CTYPE_COMPUTE> get_load_to_compute_fn(
252252
}
253253

254254
template <typename CTYPE_COMPUTE, const char* op_name>
255-
store_compute_to_tensor_fn<CTYPE_COMPUTE> get_store_compute_to_tensor_fn(
255+
store_compute_to_tensor_fn<CTYPE_COMPUTE> get_store_compute_to_tensor_fn_impl(
256256
const Tensor& t,
257257
SupportedTensorDtypes dtypes) {
258258
switch (dtypes) {
@@ -285,6 +285,37 @@ store_compute_to_tensor_fn<CTYPE_COMPUTE> get_store_compute_to_tensor_fn(
285285
return nullptr;
286286
}
287287

288+
#ifndef EXECUTORCH_SELECTIVE_BUILD_DTYPE
289+
constexpr const char kGenericElementwiseOpName[] = "generic_elementwise_op";
290+
#endif // EXECUTORCH_SELECTIVE_BUILD_DTYPE
291+
292+
template <typename CTYPE_COMPUTE, const char* op_name>
293+
load_to_compute_fn<CTYPE_COMPUTE> get_load_to_compute_fn(
294+
const Tensor& t,
295+
SupportedTensorDtypes dtypes) {
296+
return get_load_to_compute_fn_impl<
297+
CTYPE_COMPUTE,
298+
#ifdef EXECUTORCH_SELECTIVE_BUILD_DTYPE
299+
op_name
300+
#else // EXECUTORCH_SELECTIVE_BUILD_DTYPE
301+
kGenericElementwiseOpName
302+
#endif // EXECUTORCH_SELECTIVE_BUILD_DTYPE
303+
>(t, dtypes);
304+
}
305+
306+
template <typename CTYPE_COMPUTE, const char* op_name>
307+
store_compute_to_tensor_fn<CTYPE_COMPUTE> get_store_compute_to_tensor_fn(
308+
const Tensor& t,
309+
SupportedTensorDtypes dtypes) {
310+
return get_store_compute_to_tensor_fn_impl<
311+
CTYPE_COMPUTE,
312+
#ifdef EXECUTORCH_SELECTIVE_BUILD_DTYPE
313+
op_name
314+
#else // EXECUTORCH_SELECTIVE_BUILD_DTYPE
315+
kGenericElementwiseOpName
316+
#endif // EXECUTORCH_SELECTIVE_BUILD_DTYPE
317+
>(t, dtypes);
318+
}
288319
bool check_tensor_dtype(
289320
const Tensor t,
290321
SupportedTensorDtypes dtypes,

0 commit comments

Comments
 (0)