Implement TF2 and add, mul and div benchmark

This commit is contained in:
Corentin 2021-09-28 02:59:53 +09:00
commit 4b2bcfe7e8
18 changed files with 649 additions and 171 deletions

34
src/tf_2/mul.py Normal file
View file

@ -0,0 +1,34 @@
from pathlib import Path
import tensorflow as tf
from src.common import DataType, Op
from src.tf_2.base import TFBase
class TFMulBench(TFBase):
def __init__(self, output_path: Path):
super().__init__(output_path, Op.MUL)
def experiment(self, experiment_args: tuple[int, int], length: int, dtype: tf.DType, device: tf.device):
shape_1 = experiment_args
with device:
tensor_1 = tf.ones(shape_1, dtype=dtype)
tensor_2 = tf.ones(shape_1, dtype=dtype)
for _ in range(length):
_ = tensor_1 * tensor_2
def name(self, experiment_args: tuple[int, int]) -> str:
shape_1 = experiment_args
return f'{shape_1[0]}x{shape_1[1]} * {shape_1[0]}x{shape_1[1]}'
def mop(self, experiment_args: tuple[int, int]) -> float:
shape_1 = experiment_args
return shape_1[0] * shape_1[1] / 1000_000
def run(self,
experiment_args: list[tuple[int, int]],
experiment_count: int,
data_type: DataType):
super().run(experiment_args, experiment_count, data_type)