Skip to content

Commit 40a02e2

Browse files
smessmerfacebook-github-bot
authored andcommitted
Make out ops c10-full (with hacky-wrapper) (#48912)
Summary: Pull Request resolved: #48912 ghstack-source-id: 118619234 (Note: this ignores all push blocking failures!) Test Plan: Benchmark: --- Old (i.e. codegenerated unboxing wrapper + no hacky_wrapper): ``` <torch.utils.benchmark.utils.valgrind_wrapper.timer_interface.CallgrindStats object at 0x7f64d03ebcd0> torch.absolute(t, out=o) setup: t = torch.empty([1]) o = torch.empty([1]) All Noisy symbols removed Instructions: 657204 634396 Baseline: 4192 3786 100 runs per measurement, 1 thread ``` New (i.e. templated unboxing wrapper + hacky_wrapper): ``` <torch.utils.benchmark.utils.valgrind_wrapper.timer_interface.CallgrindStats object at 0x7fa7de211cd0> torch.absolute(t, out=o) setup: t = torch.empty([1]) o = torch.empty([1]) All Noisy symbols removed Instructions: 658160 633996 Baseline: 4210 3786 100 runs per measurement, 1 threa ``` Reviewed By: bhosmer Differential Revision: D25363335 fbshipit-source-id: ab9c122491e4209a49254dad0f7b3adb677b2c53
1 parent 1133428 commit 40a02e2

2 files changed

Lines changed: 373 additions & 23 deletions

File tree

aten/src/ATen/core/op_registration/hacky_wrapper_for_legacy_signatures.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,24 +262,30 @@ struct with_out_arguments_reordered_impl final {
262262
// the KernelFunction types, but for arguments we get schema order arguments and need to generate
263263
// the KernelFunction arguments.
264264
// That's why in this reordering, we use NumOutParameters instead of the num_nonout_parameters we used above.
265-
using target_signature_parameters = guts::typelist::concat_t<
265+
using schema_parameters = guts::typelist::concat_t<
266266
guts::typelist::drop_t<typename kernel_signature_traits::parameter_types, NumOutParameters>,
267267
guts::typelist::take_t<typename kernel_signature_traits::parameter_types, NumOutParameters>
268268
>;
269269

270-
template<class Return, class ParameterList, class IndexPermutation>
270+
template<class Return, class SchemaParameterList, class KernelParameterList, class IndexPermutation>
271271
struct wrapper_;
272-
template<class Return, class... Parameters, size_t... Indices>
273-
struct wrapper_<Return, guts::typelist::typelist<Parameters...>, std::index_sequence<Indices...>> {
274-
static Return call(Parameters... args) {
272+
template<class Return, class... SchemaParameters, class... KernelParameters, size_t... Indices>
273+
struct wrapper_<Return, guts::typelist::typelist<SchemaParameters...>, guts::typelist::typelist<KernelParameters...>, std::index_sequence<Indices...>> {
274+
static Return call(SchemaParameters... args) {
275275
// call through to KernelFunc but reorder arguments as determined
276276
// by the permutation we calculated above.
277-
return (*KernelFunc::func_ptr())(std::get<Indices>(std::tuple<Parameters...>(std::forward<Parameters>(args)...))...);
277+
return (*KernelFunc::func_ptr())(
278+
std::forward<KernelParameters>(
279+
std::get<Indices>(
280+
std::tuple<std::add_lvalue_reference_t<SchemaParameters>...>(args...)
281+
)
282+
)...
283+
);
278284
}
279285
};
280286

281287
public:
282-
using wrapper = wrapper_<typename kernel_signature_traits::return_type, target_signature_parameters, kernel_to_schema_permutation_indices>;
288+
using wrapper = wrapper_<typename kernel_signature_traits::return_type, schema_parameters, typename kernel_signature_traits::parameter_types, kernel_to_schema_permutation_indices>;
283289
};
284290

285291

0 commit comments

Comments
 (0)