pytorch/benchmarks/tensorexpr/swish.py
Kevin Stephano 26a91a9f04 [WIP][JIT] Add benchmarking support of NV Fuser with FP16 dtype support (#44101)
Summary:
Modified files in `benchmarks/tensorexpr` to add support for NVIDIA's Fuser for the jit compiler.

This support has some modifications besides adding an option to support the NVIDIA fuser:

* Adds FP16 Datatype support
* Fixes SOL/Algo calculations to generally use the data type instead of being fixed to 4 bytes
* Adds IR printing and kernel printing knobs
* Adds a knob `input_iter` to create ranges of inputs currently only for reductions
* Adds further reduction support for Inner and Outer dimension reductions that are compatible with the `input_iter` knob.
* Added `simple_element`, `reduce2d_inner`, and `reduce2d_outer` to isolate performance on elementwise  and reduction operations in the most minimal fashion.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/44101

Reviewed By: ngimel

Differential Revision: D23713658

Pulled By: bertmaher

fbshipit-source-id: d6b83cfab559aefe107c23b3c0f2df9923b3adc1
2020-09-15 15:10:49 -07:00

51 lines
1.3 KiB
Python

from . import benchmark
import torch
class SwishBench(benchmark.Benchmark):
def __init__(self, mode, device, dtype, M, N):
super().__init__(mode, device, dtype)
self.M = M
self.N = N
self.data = self.rand([M, N], device=device, dtype=dtype, requires_grad=self.requires_grad)
self.inputs = [self.data]
self.zeros = torch.zeros(M, N, device=device)
self.six = self.zeros + 6.0
self.three = self.zeros + 3.0
self.sixth = self.zeros + 1.0 / 6.0
def forward(self, inp):
y = inp * (torch.min(torch.relu(inp), self.six) + self.three) * self.sixth
return y
def reference(self):
return self.numpy(self.forward(self.data))
def config(self):
return [self.M, self.N]
@staticmethod
def module():
return "swish"
def memory_workload(self):
if self.mode == "fwd":
sol_count = 1 + 1
algorithmic_count = 3 + 1
else:
sol_count = (1 + 1) + (1 + 1)
algorithmic_count = (3 + 1) + (3 + 1)
buffer_size = self.M * self.N
return {
"sol": buffer_size * sol_count,
"algorithmic": buffer_size * algorithmic_count,
}
@staticmethod
def default_configs():
return [[128, 1 << 16]]
benchmark.register_benchmark_class(SwishBench)