Skip to content

Commit ba152c3

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: 021f467604b1077fa7957d76dd3d81d2362cdaef ghstack-comment-id: 2761913331 Pull-Request-resolved: #9742 ghstack-source-id: 021f467604b1077fa7957d76dd3d81d2362cdaef ghstack-comment-id: 2773214759 Pull Request resolved: #9842
1 parent e8e5977 commit ba152c3

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

kernels/portable/cpu/util/dtype_util.h

+33-2
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)