99#include < c10/util/Optional.h>
1010#include < torch/csrc/autograd/custom_function.h>
1111#include < torch/csrc/autograd/function.h>
12+ #include < torch/csrc/autograd/record_function.h>
1213#include < torch/csrc/autograd/variable.h>
1314#include < torch/script.h>
1415
1516class NewLinearOp : public torch ::autograd::Function<NewLinearOp> {
1617public:
1718 static at::Tensor _forward (at::Tensor input, at::Tensor weight,
1819 at::Tensor bias = at::Tensor()) {
20+ #if defined(IPEX_PROFILE_OP)
21+ RECORD_FUNCTION (" IPEXLinearOp::_forward" , std::vector<c10::IValue>({input, weight, bias}), torch::autograd::Node::peek_at_next_sequence_nr ());
22+ #endif
1923 try {
2024 if (torch_ipex::check_auto_dnnl () &&
2125 input.device ().type () == c10::DeviceType::DPCPP) {
@@ -48,13 +52,19 @@ class NewLinearOp : public torch::autograd::Function<NewLinearOp> {
4852 static at::Tensor forward (torch::autograd::AutogradContext *ctx,
4953 at::Tensor input, at::Tensor weight,
5054 at::Tensor bias = at::Tensor()) {
55+ #if defined(IPEX_PROFILE_OP)
56+ RECORD_FUNCTION (" IPEXLinearOp::forward" , std::vector<c10::IValue>({input, weight, bias}), torch::autograd::Node::peek_at_next_sequence_nr ());
57+ #endif
5158 ctx->save_for_backward ({input, weight, bias});
5259 return _forward (input, weight, bias);
5360 }
5461
5562 static torch::autograd::tensor_list
5663 backward (torch::autograd::AutogradContext *ctx,
5764 torch::autograd::tensor_list grad_outputs) {
65+ #if defined(IPEX_PROFILE_OP)
66+ RECORD_FUNCTION (" IPEXLinearOp::backward" , std::vector<c10::IValue>({}), torch::autograd::Node::peek_at_next_sequence_nr ());
67+ #endif
5868 auto saved = ctx->get_saved_variables ();
5969 at::Tensor input = saved[0 ];
6070 at::Tensor weight = saved[1 ];
@@ -149,6 +159,9 @@ class NewMaxPool2dOp : public torch::autograd::Function<NewMaxPool2dOp> {
149159 _forward (at::Tensor input, at::IntArrayRef kernel_size,
150160 at::IntArrayRef stride, at::IntArrayRef padding,
151161 at::IntArrayRef dilation, bool ceil_mode) {
162+ #if defined(IPEX_PROFILE_OP)
163+ RECORD_FUNCTION (" IPEXMaxPool2dOp::_forward" , std::vector<c10::IValue>({input}), torch::autograd::Node::peek_at_next_sequence_nr ());
164+ #endif
152165 try {
153166 if (torch_ipex::check_auto_dnnl () &&
154167 input.device ().type () == c10::DeviceType::DPCPP) {
@@ -187,6 +200,9 @@ class NewMaxPool2dOp : public torch::autograd::Function<NewMaxPool2dOp> {
187200 at::Tensor input, at::IntArrayRef kernel_size,
188201 at::IntArrayRef stride, at::IntArrayRef padding,
189202 at::IntArrayRef dilation, bool ceil_mode) {
203+ #if defined(IPEX_PROFILE_OP)
204+ RECORD_FUNCTION (" IPEXMaxPool2dOp::forward" , std::vector<c10::IValue>({input}), torch::autograd::Node::peek_at_next_sequence_nr ());
205+ #endif
190206 ctx->saved_data [" kernel_size" ] = kernel_size;
191207 ctx->saved_data [" stride" ] = stride;
192208 ctx->saved_data [" padding" ] = padding;
@@ -203,6 +219,9 @@ class NewMaxPool2dOp : public torch::autograd::Function<NewMaxPool2dOp> {
203219 static torch::autograd::tensor_list
204220 backward (torch::autograd::AutogradContext *ctx,
205221 torch::autograd::tensor_list grad_outputs) {
222+ #if defined(IPEX_PROFILE_OP)
223+ RECORD_FUNCTION (" IPEXMaxPool2dOp::backward" , std::vector<c10::IValue>({}), torch::autograd::Node::peek_at_next_sequence_nr ());
224+ #endif
206225 auto saved = ctx->get_saved_variables ();
207226 at::Tensor input = saved[0 ];
208227 at::Tensor indices = saved[1 ];
@@ -263,6 +282,9 @@ class NewMaxPool3dOp : public torch::autograd::Function<NewMaxPool3dOp> {
263282 _forward (at::Tensor input, at::IntArrayRef kernel_size,
264283 at::IntArrayRef stride, at::IntArrayRef padding,
265284 at::IntArrayRef dilation, bool ceil_mode) {
285+ #if defined(IPEX_PROFILE_OP)
286+ RECORD_FUNCTION (" IPEXMaxPool3dOp::_forward" , std::vector<c10::IValue>({input}), torch::autograd::Node::peek_at_next_sequence_nr ());
287+ #endif
266288 try {
267289 if (torch_ipex::check_auto_dnnl () &&
268290 input.device ().type () == c10::DeviceType::DPCPP) {
@@ -298,6 +320,9 @@ class NewMaxPool3dOp : public torch::autograd::Function<NewMaxPool3dOp> {
298320 at::Tensor input, at::IntArrayRef kernel_size,
299321 at::IntArrayRef stride, at::IntArrayRef padding,
300322 at::IntArrayRef dilation, bool ceil_mode) {
323+ #if defined(IPEX_PROFILE_OP)
324+ RECORD_FUNCTION (" IPEXMaxPool3dOp::forward" , std::vector<c10::IValue>({input}), torch::autograd::Node::peek_at_next_sequence_nr ());
325+ #endif
301326 ctx->saved_data [" kernel_size" ] = kernel_size;
302327 ctx->saved_data [" stride" ] = stride;
303328 ctx->saved_data [" padding" ] = padding;
@@ -314,6 +339,9 @@ class NewMaxPool3dOp : public torch::autograd::Function<NewMaxPool3dOp> {
314339 static torch::autograd::tensor_list
315340 backward (torch::autograd::AutogradContext *ctx,
316341 torch::autograd::tensor_list grad_outputs) {
342+ #if defined(IPEX_PROFILE_OP)
343+ RECORD_FUNCTION (" IPEXMaxPool3dOp::backward" , std::vector<c10::IValue>({}), torch::autograd::Node::peek_at_next_sequence_nr ());
344+ #endif
317345 auto saved = ctx->get_saved_variables ();
318346 at::Tensor input = saved[0 ];
319347 at::Tensor indices = saved[1 ];
@@ -372,6 +400,9 @@ class NewApaptiveAvgPoolingOp
372400 : public torch::autograd::Function<NewApaptiveAvgPoolingOp> {
373401public:
374402 static at::Tensor _forward (at::Tensor input, at::IntArrayRef output_size) {
403+ #if defined(IPEX_PROFILE_OP)
404+ RECORD_FUNCTION (" IPEXApaptiveAvgPoolingOp::_forward" , std::vector<c10::IValue>({input}), torch::autograd::Node::peek_at_next_sequence_nr ());
405+ #endif
375406 try {
376407 if (torch_ipex::check_auto_dnnl () && input.device ().type () == c10::DeviceType::DPCPP) {
377408 auto src_dil_type = torch_ipex::cpu::dbl::comm::try_gen_dil_tensor (input).get_data_type ();
@@ -397,13 +428,19 @@ class NewApaptiveAvgPoolingOp
397428
398429 static at::Tensor forward (torch::autograd::AutogradContext *ctx,
399430 at::Tensor input, at::IntArrayRef output_size) {
431+ #if defined(IPEX_PROFILE_OP)
432+ RECORD_FUNCTION (" IPEXApaptiveAvgPoolingOp::forward" , std::vector<c10::IValue>({input}), torch::autograd::Node::peek_at_next_sequence_nr ());
433+ #endif
400434 ctx->save_for_backward ({input});
401435 return _forward (input, output_size);
402436 }
403437
404438 static torch::autograd::tensor_list
405439 backward (torch::autograd::AutogradContext *ctx,
406440 torch::autograd::tensor_list grad_outputs) {
441+ #if defined(IPEX_PROFILE_OP)
442+ RECORD_FUNCTION (" IPEXApaptiveAvgPoolingOp::backward" , std::vector<c10::IValue>({}), torch::autograd::Node::peek_at_next_sequence_nr ());
443+ #endif
407444 auto saved = ctx->get_saved_variables ();
408445 at::Tensor input = saved[0 ];
409446
0 commit comments