def tick(self, key): if key not in self.times: self.times[key] = 0 if self.sync: torch.cuda.synchronize() now = micros() self.times[key] += now - self.time self.time = now
def __init__(self, torch_sync=False, print=True): """ When debugging GPU code, torch_sync must be true, because GPU and CPU computation is asynchronous :param torch_sync: If true, will call cuda synchronize. :param print: If true, will print stats when print_stats is called. Pass False to disable output for release code """ self.time = micros() self.loops = 0 self.times = {} self.avg_times = {} self.sync = torch_sync self.print = print self.print_time = 0
def reset(self): self.time = micros() self.times = {}