pytorch/torch/testing/_internal/te_utils.py
Yujun Zhao e5adf45dde Add python unittest target to caffe2/test/TARGETS (#42766)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/42766

**Summary**
Some python tests are missing in `caffe2/test/TARGETS`, add them to be more comprehension.

According to [run_test.py](https://github.com/pytorch/pytorch/blob/master/test/run_test.py#L125), some tests are slower. Slow tests are added as independent targets and others are put together into one `others` target. The reason is because we want to reduce overhead, especially for code covarge collection.  Tests in one target can be run as a bundle, and then coverage can be collected together. Typically coverage collection procedure is time-expensive, so this helps us save time.

Test Plan:
Run all the new test targets locally in dev server and record the time they cost.
**Statistics**

```
# jit target
real    33m7.694s
user    653m1.181s
sys     58m14.160s

--------- Compare to Initial Jit Target runtime: ----------------

real    32m13.057s
user    613m52.843s
sys     54m58.678s

```

```
# others target
real    9m2.920s
user    164m21.927s
sys     12m54.840s
```

```
# serialization target
real    4m21.090s
user    23m33.501s
sys     1m53.308s

```

```
# tensorexpr
real    11m28.187s
user    33m36.420s
sys     1m15.925s
```

```
# type target
real    3m36.197s
user    51m47.912s
sys     4m14.149s
```

Reviewed By: malfet

Differential Revision: D22979219

fbshipit-source-id: 12a30839bb76a64871359bc024e4bff670c5ca8b
2020-08-10 09:48:59 -07:00

42 lines
1.3 KiB
Python

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import torch
class ExecutionCounter(object):
def try_get_trigger_value(self):
try:
return torch._C._jit_get_trigger_value(self.name)
except Exception:
return 0
def __init__(self, name):
self.name = name
self.start_value = self.try_get_trigger_value()
def elapsed_value(self):
value = self.try_get_trigger_value()
return value - self.start_value
class CudaCodeGenCreated(ExecutionCounter):
def __init__(self):
super(CudaCodeGenCreated, self).__init__("cuda_codegen_created")
class CudaCodeGenExecuted(ExecutionCounter):
def __init__(self):
super(CudaCodeGenExecuted, self).__init__("cuda_codegen_executed")
class LLVMCodeGenCreated(ExecutionCounter):
def __init__(self):
super(LLVMCodeGenCreated, self).__init__("llvm_codegen_created")
class LLVMCodeGenExecuted(ExecutionCounter):
def __init__(self):
super(LLVMCodeGenExecuted, self).__init__("llvm_codegen_executed")
class SimpleIREvalExecuted(ExecutionCounter):
def __init__(self):
super(SimpleIREvalExecuted, self).__init__("simple_ir_eval_executed")